Skip to content

Commit d4c0f91

Browse files
authoredJun 6, 2017
Use C++11 mutexes only (remove compat code) (#5922)
* Fix event LINT & remove default constructor/destructors * remove compat code & modernize autolock header
1 parent 8bdde45 commit d4c0f91

36 files changed

+59
-363
lines changed
 

‎src/ban.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include "util/string.h"
2424
#include "threading/thread.h"
25-
#include "threading/mutex.h"
2625
#include "exceptions.h"
2726
#include <map>
2827
#include <string>
28+
#include <mutex>
2929

3030
class BanManager
3131
{
@@ -43,7 +43,7 @@ class BanManager
4343
bool isModified();
4444

4545
private:
46-
Mutex m_mutex;
46+
std::mutex m_mutex;
4747
std::string m_banfilepath;
4848
StringMap m_ips;
4949
bool m_modified;

‎src/client.h

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "network/connection.h"
2424
#include "clientenvironment.h"
2525
#include "irrlichttypes_extrabloated.h"
26-
#include "threading/mutex.h"
2726
#include <ostream>
2827
#include <map>
2928
#include <set>

‎src/client/clientlauncher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ void ClientLauncher::speed_tests()
657657
infostream << "Around 5000/ms should do well here." << std::endl;
658658
TimeTaker timer("Testing mutex speed");
659659

660-
Mutex m;
660+
std::mutex m;
661661
u32 n = 0;
662662
u32 i = 0;
663663
do {

‎src/client/tile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class TextureSource : public IWritableTextureSource
417417
// Maps a texture name to an index in the former.
418418
std::map<std::string, u32> m_name_to_id;
419419
// The two former containers are behind this mutex
420-
Mutex m_textureinfo_cache_mutex;
420+
std::mutex m_textureinfo_cache_mutex;
421421

422422
// Queued texture fetches (to be processed by the main thread)
423423
RequestQueue<std::string, u32, u8, u8> m_get_texture_queue;

‎src/clientiface.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323

2424
#include "constants.h"
2525
#include "serialization.h" // for SER_FMT_VER_INVALID
26-
#include "threading/mutex.h"
2726
#include "network/networkpacket.h"
2827
#include "porting.h"
2928

3029
#include <list>
3130
#include <vector>
3231
#include <set>
32+
#include <mutex>
3333

3434
class MapBlock;
3535
class ServerEnvironment;
@@ -508,14 +508,14 @@ class ClientInterface {
508508

509509
// Connection
510510
con::Connection* m_con;
511-
Mutex m_clients_mutex;
511+
std::mutex m_clients_mutex;
512512
// Connected clients (behind the con mutex)
513513
RemoteClientMap m_clients;
514514
std::vector<std::string> m_clients_names; //for announcing masterserver
515515

516516
// Environment
517517
ServerEnvironment *m_env;
518-
Mutex m_env_mutex;
518+
std::mutex m_env_mutex;
519519

520520
float m_print_info_timer;
521521

‎src/debug.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include <cstring>
2828
#include <map>
2929
#include <sstream>
30-
#include "threading/mutex.h"
3130
#include "threading/mutex_auto_lock.h"
3231
#include "config.h"
3332

@@ -152,7 +151,7 @@ void DebugStack::print(std::ostream &os, bool everything)
152151
// pthread_t, but it isn't too important since none of our supported platforms
153152
// implement pthread_t as a non-ordinal type.
154153
std::map<threadid_t, DebugStack*> g_debug_stacks;
155-
Mutex g_debug_stacks_mutex;
154+
std::mutex g_debug_stacks_mutex;
156155

157156
void debug_stacks_init()
158157
{

‎src/emerge.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#define EMERGE_HEADER
2222

2323
#include <map>
24+
#include <mutex>
2425
#include "irr_v3d.h"
2526
#include "util/container.h"
2627
#include "mapgen.h" // for MapgenParams
@@ -155,7 +156,7 @@ class EmergeManager {
155156
std::vector<EmergeThread *> m_threads;
156157
bool m_threads_active;
157158

158-
Mutex m_queue_mutex;
159+
std::mutex m_queue_mutex;
159160
std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
160161
std::unordered_map<u16, u16> m_peer_queue_count;
161162

‎src/environment.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#include <queue>
3535
#include <map>
3636
#include <atomic>
37+
#include <mutex>
3738
#include "irr_v3d.h"
3839
#include "activeobject.h"
3940
#include "util/numeric.h"
40-
#include "threading/mutex.h"
4141
#include "network/networkprotocol.h" // for AccessDeniedCode
4242

4343
class IGameDef;
@@ -120,7 +120,7 @@ class Environment
120120
IGameDef *m_gamedef;
121121

122122
private:
123-
Mutex m_time_lock;
123+
std::mutex m_time_lock;
124124

125125
DISABLE_CLASS_COPY(Environment);
126126
};

‎src/face_position_cache.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323

2424
std::unordered_map<u16, std::vector<v3s16>> FacePositionCache::cache;
25-
Mutex FacePositionCache::cache_mutex;
25+
std::mutex FacePositionCache::cache_mutex;
2626

2727
// Calculate the borders of a "d-radius" cube
2828
const std::vector<v3s16> &FacePositionCache::getFacePositions(u16 d)

‎src/face_position_cache.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#define FACE_POSITION_CACHE_HEADER
2222

2323
#include "irr_v3d.h"
24-
#include "threading/mutex.h"
2524

2625
#include <map>
2726
#include <vector>
2827
#include <unordered_map>
28+
#include <mutex>
2929

3030
/*
3131
* This class permits caching getFacePosition call results.
@@ -38,7 +38,7 @@ class FacePositionCache {
3838
private:
3939
static const std::vector<v3s16> &generateFacePosition(u16 d);
4040
static std::unordered_map<u16, std::vector<v3s16>> cache;
41-
static Mutex cache_mutex;
41+
static std::mutex cache_mutex;
4242
};
4343

4444
#endif

‎src/httpfetch.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include <list>
2626
#include <map>
2727
#include <errno.h>
28+
#include <mutex>
2829
#include "threading/event.h"
2930
#include "config.h"
3031
#include "exceptions.h"
@@ -36,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3637
#include "settings.h"
3738
#include "noise.h"
3839

39-
Mutex g_httpfetch_mutex;
40+
std::mutex g_httpfetch_mutex;
4041
std::map<unsigned long, std::queue<HTTPFetchResult> > g_httpfetch_results;
4142
PcgRandom g_callerid_randomness;
4243

‎src/log.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include <queue>
2525
#include <string>
2626
#include <fstream>
27+
#include <mutex>
2728
#include "threads.h"
2829
#include "irrlichttypes.h"
2930

@@ -79,7 +80,7 @@ class Logger {
7980
// Works on all known architectures (x86, ARM, MIPS).
8081
volatile bool m_silenced_levels[LL_MAX];
8182
std::map<threadid_t, std::string> m_thread_names;
82-
mutable Mutex m_mutex;
83+
mutable std::mutex m_mutex;
8384
bool m_trace_enabled;
8485
};
8586

‎src/mesh_generator_thread.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
#ifndef MESH_GENERATOR_THREAD_HEADER
2121
#define MESH_GENERATOR_THREAD_HEADER
2222

23+
#include <mutex>
2324
#include "mapblock_mesh.h"
2425
#include "threading/mutex_auto_lock.h"
2526
#include "util/thread.h"
@@ -83,7 +84,7 @@ class MeshUpdateQueue
8384
std::vector<QueuedMeshUpdate *> m_queue;
8485
std::set<v3s16> m_urgents;
8586
std::map<v3s16, CachedMapBlockData *> m_cache;
86-
Mutex m_mutex;
87+
std::mutex m_mutex;
8788

8889
// TODO: Add callback to update these when g_settings changes
8990
bool m_cache_enable_shaders;

‎src/minimap.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "irrlichttypes_extrabloated.h"
2424
#include "client.h"
2525
#include "voxel.h"
26-
#include "threading/mutex.h"
2726
#include "threading/semaphore.h"
2827
#include <map>
2928
#include <string>
@@ -112,7 +111,7 @@ class MinimapUpdateThread : public UpdateThread {
112111
virtual void doUpdate();
113112

114113
private:
115-
Mutex m_queue_mutex;
114+
std::mutex m_queue_mutex;
116115
std::deque<QueuedMinimapUpdate> m_update_queue;
117116
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
118117
};
@@ -161,7 +160,7 @@ class Minimap {
161160
bool m_enable_shaders;
162161
u16 m_surface_mode_scan_height;
163162
f32 m_angle;
164-
Mutex m_mutex;
163+
std::mutex m_mutex;
165164
std::list<v2f> m_active_markers;
166165
};
167166

‎src/network/connection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace con
4242
#undef DEBUG_CONNECTION_KBPS
4343
#else
4444
/* this mutex is used to achieve log message consistency */
45-
Mutex log_message_mutex;
45+
std::mutex log_message_mutex;
4646
#define LOG(a) \
4747
{ \
4848
MutexAutoLock loglock(log_message_mutex); \

‎src/network/connection.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class ReliablePacketBuffer
349349

350350
u16 m_oldest_non_answered_ack;
351351

352-
Mutex m_list_mutex;
352+
std::mutex m_list_mutex;
353353
};
354354

355355
/*
@@ -372,7 +372,7 @@ class IncomingSplitBuffer
372372
// Key is seqnum
373373
std::map<u16, IncomingSplitPacket*> m_buf;
374374

375-
Mutex m_map_mutex;
375+
std::mutex m_map_mutex;
376376
};
377377

378378
struct OutgoingPacket
@@ -544,7 +544,7 @@ class Channel
544544

545545
void setWindowSize(unsigned int size) { window_size = size; };
546546
private:
547-
Mutex m_internal_mutex;
547+
std::mutex m_internal_mutex;
548548
int window_size;
549549

550550
u16 next_incoming_seqnum;
@@ -738,7 +738,7 @@ class Peer {
738738
bool IncUseCount();
739739
void DecUseCount();
740740

741-
Mutex m_exclusive_access_mutex;
741+
std::mutex m_exclusive_access_mutex;
742742

743743
bool m_pending_deletion;
744744

@@ -1064,12 +1064,12 @@ class Connection
10641064

10651065
std::map<u16, Peer*> m_peers;
10661066
std::list<u16> m_peer_ids;
1067-
Mutex m_peers_mutex;
1067+
std::mutex m_peers_mutex;
10681068

10691069
ConnectionSendThread m_sendThread;
10701070
ConnectionReceiveThread m_receiveThread;
10711071

1072-
Mutex m_info_mutex;
1072+
std::mutex m_info_mutex;
10731073

10741074
// Backwards compatibility
10751075
PeerHandler *m_bc_peerhandler;

‎src/particles.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ friend class ParticleSpawner;
213213
std::map<u32, ParticleSpawner*> m_particle_spawners;
214214

215215
ClientEnvironment* m_env;
216-
Mutex m_particle_list_lock;
217-
Mutex m_spawner_list_lock;
216+
std::mutex m_particle_list_lock;
217+
std::mutex m_spawner_list_lock;
218218
};
219219

220220
#endif

‎src/player.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include "irrlichttypes_bloated.h"
2424
#include "inventory.h"
25-
#include "threading/mutex.h"
2625
#include <list>
26+
#include <mutex>
2727

2828
#define PLAYERNAME_SIZE 20
2929

@@ -186,7 +186,7 @@ class Player
186186
// Protect some critical areas
187187
// hud for example can be modified by EmergeThread
188188
// and ServerThread
189-
Mutex m_mutex;
189+
std::mutex m_mutex;
190190
};
191191

192192
#endif

‎src/profiler.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include <string>
2525
#include <map>
2626

27-
#include "threading/mutex.h"
2827
#include "threading/mutex_auto_lock.h"
2928
#include "util/timetaker.h"
3029
#include "util/numeric.h" // paging()
@@ -177,7 +176,7 @@ class Profiler
177176
}
178177

179178
private:
180-
Mutex m_mutex;
179+
std::mutex m_mutex;
181180
std::map<std::string, float> m_data;
182181
std::map<std::string, int> m_avgcounts;
183182
std::map<std::string, float> m_graphvalues;

‎src/quicktune.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "quicktune.h"
21-
#include "threading/mutex.h"
2221
#include "threading/mutex_auto_lock.h"
2322
#include "util/string.h"
2423

@@ -49,12 +48,12 @@ void QuicktuneValue::relativeAdd(float amount)
4948

5049
static std::map<std::string, QuicktuneValue> g_values;
5150
static std::vector<std::string> g_names;
52-
Mutex *g_mutex = NULL;
51+
std::mutex *g_mutex = NULL;
5352

5453
static void makeMutex()
5554
{
5655
if(!g_mutex){
57-
g_mutex = new Mutex();
56+
g_mutex = new std::mutex();
5857
}
5958
}
6059

‎src/script/cpp_api/s_async.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include <map>
2626

2727
#include "threading/thread.h"
28-
#include "threading/mutex.h"
2928
#include "threading/semaphore.h"
3029
#include "debug.h"
3130
#include "lua.h"
@@ -147,13 +146,13 @@ class AsyncEngine {
147146
unsigned int jobIdCounter;
148147

149148
// Mutex to protect job queue
150-
Mutex jobQueueMutex;
149+
std::mutex jobQueueMutex;
151150

152151
// Job queue
153152
std::deque<LuaJobInfo> jobQueue;
154153

155154
// Mutex to protect result queue
156-
Mutex resultQueueMutex;
155+
std::mutex resultQueueMutex;
157156
// Result queue
158157
std::deque<LuaJobInfo> resultQueue;
159158

0 commit comments

Comments
 (0)
Please sign in to comment.