Skip to content

Commit

Permalink
Use C++11 mutexes only (remove compat code) (#5922)
Browse files Browse the repository at this point in the history
* Fix event LINT & remove default constructor/destructors
* remove compat code & modernize autolock header
  • Loading branch information
nerzhul committed Jun 6, 2017
1 parent 8bdde45 commit d4c0f91
Show file tree
Hide file tree
Showing 36 changed files with 59 additions and 363 deletions.
4 changes: 2 additions & 2 deletions src/ban.h
Expand Up @@ -22,10 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "util/string.h"
#include "threading/thread.h"
#include "threading/mutex.h"
#include "exceptions.h"
#include <map>
#include <string>
#include <mutex>

class BanManager
{
Expand All @@ -43,7 +43,7 @@ class BanManager
bool isModified();

private:
Mutex m_mutex;
std::mutex m_mutex;
std::string m_banfilepath;
StringMap m_ips;
bool m_modified;
Expand Down
1 change: 0 additions & 1 deletion src/client.h
Expand Up @@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "network/connection.h"
#include "clientenvironment.h"
#include "irrlichttypes_extrabloated.h"
#include "threading/mutex.h"
#include <ostream>
#include <map>
#include <set>
Expand Down
2 changes: 1 addition & 1 deletion src/client/clientlauncher.cpp
Expand Up @@ -657,7 +657,7 @@ void ClientLauncher::speed_tests()
infostream << "Around 5000/ms should do well here." << std::endl;
TimeTaker timer("Testing mutex speed");

Mutex m;
std::mutex m;
u32 n = 0;
u32 i = 0;
do {
Expand Down
2 changes: 1 addition & 1 deletion src/client/tile.cpp
Expand Up @@ -417,7 +417,7 @@ class TextureSource : public IWritableTextureSource
// Maps a texture name to an index in the former.
std::map<std::string, u32> m_name_to_id;
// The two former containers are behind this mutex
Mutex m_textureinfo_cache_mutex;
std::mutex m_textureinfo_cache_mutex;

// Queued texture fetches (to be processed by the main thread)
RequestQueue<std::string, u32, u8, u8> m_get_texture_queue;
Expand Down
6 changes: 3 additions & 3 deletions src/clientiface.h
Expand Up @@ -23,13 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "constants.h"
#include "serialization.h" // for SER_FMT_VER_INVALID
#include "threading/mutex.h"
#include "network/networkpacket.h"
#include "porting.h"

#include <list>
#include <vector>
#include <set>
#include <mutex>

class MapBlock;
class ServerEnvironment;
Expand Down Expand Up @@ -508,14 +508,14 @@ class ClientInterface {

// Connection
con::Connection* m_con;
Mutex m_clients_mutex;
std::mutex m_clients_mutex;
// Connected clients (behind the con mutex)
RemoteClientMap m_clients;
std::vector<std::string> m_clients_names; //for announcing masterserver

// Environment
ServerEnvironment *m_env;
Mutex m_env_mutex;
std::mutex m_env_mutex;

float m_print_info_timer;

Expand Down
3 changes: 1 addition & 2 deletions src/debug.cpp
Expand Up @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cstring>
#include <map>
#include <sstream>
#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "config.h"

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

void debug_stacks_init()
{
Expand Down
3 changes: 2 additions & 1 deletion src/emerge.h
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define EMERGE_HEADER

#include <map>
#include <mutex>
#include "irr_v3d.h"
#include "util/container.h"
#include "mapgen.h" // for MapgenParams
Expand Down Expand Up @@ -155,7 +156,7 @@ class EmergeManager {
std::vector<EmergeThread *> m_threads;
bool m_threads_active;

Mutex m_queue_mutex;
std::mutex m_queue_mutex;
std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
std::unordered_map<u16, u16> m_peer_queue_count;

Expand Down
4 changes: 2 additions & 2 deletions src/environment.h
Expand Up @@ -34,10 +34,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <queue>
#include <map>
#include <atomic>
#include <mutex>
#include "irr_v3d.h"
#include "activeobject.h"
#include "util/numeric.h"
#include "threading/mutex.h"
#include "network/networkprotocol.h" // for AccessDeniedCode

class IGameDef;
Expand Down Expand Up @@ -120,7 +120,7 @@ class Environment
IGameDef *m_gamedef;

private:
Mutex m_time_lock;
std::mutex m_time_lock;

DISABLE_CLASS_COPY(Environment);
};
Expand Down
2 changes: 1 addition & 1 deletion src/face_position_cache.cpp
Expand Up @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,


std::unordered_map<u16, std::vector<v3s16>> FacePositionCache::cache;
Mutex FacePositionCache::cache_mutex;
std::mutex FacePositionCache::cache_mutex;

// Calculate the borders of a "d-radius" cube
const std::vector<v3s16> &FacePositionCache::getFacePositions(u16 d)
Expand Down
4 changes: 2 additions & 2 deletions src/face_position_cache.h
Expand Up @@ -21,11 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define FACE_POSITION_CACHE_HEADER

#include "irr_v3d.h"
#include "threading/mutex.h"

#include <map>
#include <vector>
#include <unordered_map>
#include <mutex>

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

#endif
3 changes: 2 additions & 1 deletion src/httpfetch.cpp
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <list>
#include <map>
#include <errno.h>
#include <mutex>
#include "threading/event.h"
#include "config.h"
#include "exceptions.h"
Expand All @@ -36,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "noise.h"

Mutex g_httpfetch_mutex;
std::mutex g_httpfetch_mutex;
std::map<unsigned long, std::queue<HTTPFetchResult> > g_httpfetch_results;
PcgRandom g_callerid_randomness;

Expand Down
3 changes: 2 additions & 1 deletion src/log.h
Expand Up @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <queue>
#include <string>
#include <fstream>
#include <mutex>
#include "threads.h"
#include "irrlichttypes.h"

Expand Down Expand Up @@ -79,7 +80,7 @@ class Logger {
// Works on all known architectures (x86, ARM, MIPS).
volatile bool m_silenced_levels[LL_MAX];
std::map<threadid_t, std::string> m_thread_names;
mutable Mutex m_mutex;
mutable std::mutex m_mutex;
bool m_trace_enabled;
};

Expand Down
3 changes: 2 additions & 1 deletion src/mesh_generator_thread.h
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef MESH_GENERATOR_THREAD_HEADER
#define MESH_GENERATOR_THREAD_HEADER

#include <mutex>
#include "mapblock_mesh.h"
#include "threading/mutex_auto_lock.h"
#include "util/thread.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ class MeshUpdateQueue
std::vector<QueuedMeshUpdate *> m_queue;
std::set<v3s16> m_urgents;
std::map<v3s16, CachedMapBlockData *> m_cache;
Mutex m_mutex;
std::mutex m_mutex;

// TODO: Add callback to update these when g_settings changes
bool m_cache_enable_shaders;
Expand Down
5 changes: 2 additions & 3 deletions src/minimap.h
Expand Up @@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "client.h"
#include "voxel.h"
#include "threading/mutex.h"
#include "threading/semaphore.h"
#include <map>
#include <string>
Expand Down Expand Up @@ -112,7 +111,7 @@ class MinimapUpdateThread : public UpdateThread {
virtual void doUpdate();

private:
Mutex m_queue_mutex;
std::mutex m_queue_mutex;
std::deque<QueuedMinimapUpdate> m_update_queue;
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
};
Expand Down Expand Up @@ -161,7 +160,7 @@ class Minimap {
bool m_enable_shaders;
u16 m_surface_mode_scan_height;
f32 m_angle;
Mutex m_mutex;
std::mutex m_mutex;
std::list<v2f> m_active_markers;
};

Expand Down
2 changes: 1 addition & 1 deletion src/network/connection.cpp
Expand Up @@ -42,7 +42,7 @@ namespace con
#undef DEBUG_CONNECTION_KBPS
#else
/* this mutex is used to achieve log message consistency */
Mutex log_message_mutex;
std::mutex log_message_mutex;
#define LOG(a) \
{ \
MutexAutoLock loglock(log_message_mutex); \
Expand Down
12 changes: 6 additions & 6 deletions src/network/connection.h
Expand Up @@ -349,7 +349,7 @@ class ReliablePacketBuffer

u16 m_oldest_non_answered_ack;

Mutex m_list_mutex;
std::mutex m_list_mutex;
};

/*
Expand All @@ -372,7 +372,7 @@ class IncomingSplitBuffer
// Key is seqnum
std::map<u16, IncomingSplitPacket*> m_buf;

Mutex m_map_mutex;
std::mutex m_map_mutex;
};

struct OutgoingPacket
Expand Down Expand Up @@ -544,7 +544,7 @@ class Channel

void setWindowSize(unsigned int size) { window_size = size; };
private:
Mutex m_internal_mutex;
std::mutex m_internal_mutex;
int window_size;

u16 next_incoming_seqnum;
Expand Down Expand Up @@ -738,7 +738,7 @@ class Peer {
bool IncUseCount();
void DecUseCount();

Mutex m_exclusive_access_mutex;
std::mutex m_exclusive_access_mutex;

bool m_pending_deletion;

Expand Down Expand Up @@ -1064,12 +1064,12 @@ class Connection

std::map<u16, Peer*> m_peers;
std::list<u16> m_peer_ids;
Mutex m_peers_mutex;
std::mutex m_peers_mutex;

ConnectionSendThread m_sendThread;
ConnectionReceiveThread m_receiveThread;

Mutex m_info_mutex;
std::mutex m_info_mutex;

// Backwards compatibility
PeerHandler *m_bc_peerhandler;
Expand Down
4 changes: 2 additions & 2 deletions src/particles.h
Expand Up @@ -213,8 +213,8 @@ friend class ParticleSpawner;
std::map<u32, ParticleSpawner*> m_particle_spawners;

ClientEnvironment* m_env;
Mutex m_particle_list_lock;
Mutex m_spawner_list_lock;
std::mutex m_particle_list_lock;
std::mutex m_spawner_list_lock;
};

#endif
4 changes: 2 additions & 2 deletions src/player.h
Expand Up @@ -22,8 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "irrlichttypes_bloated.h"
#include "inventory.h"
#include "threading/mutex.h"
#include <list>
#include <mutex>

#define PLAYERNAME_SIZE 20

Expand Down Expand Up @@ -186,7 +186,7 @@ class Player
// Protect some critical areas
// hud for example can be modified by EmergeThread
// and ServerThread
Mutex m_mutex;
std::mutex m_mutex;
};

#endif
Expand Down
3 changes: 1 addition & 2 deletions src/profiler.h
Expand Up @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include <map>

#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "util/timetaker.h"
#include "util/numeric.h" // paging()
Expand Down Expand Up @@ -177,7 +176,7 @@ class Profiler
}

private:
Mutex m_mutex;
std::mutex m_mutex;
std::map<std::string, float> m_data;
std::map<std::string, int> m_avgcounts;
std::map<std::string, float> m_graphvalues;
Expand Down
5 changes: 2 additions & 3 deletions src/quicktune.cpp
Expand Up @@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "quicktune.h"
#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "util/string.h"

Expand Down Expand Up @@ -49,12 +48,12 @@ void QuicktuneValue::relativeAdd(float amount)

static std::map<std::string, QuicktuneValue> g_values;
static std::vector<std::string> g_names;
Mutex *g_mutex = NULL;
std::mutex *g_mutex = NULL;

static void makeMutex()
{
if(!g_mutex){
g_mutex = new Mutex();
g_mutex = new std::mutex();
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/script/cpp_api/s_async.h
Expand Up @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>

#include "threading/thread.h"
#include "threading/mutex.h"
#include "threading/semaphore.h"
#include "debug.h"
#include "lua.h"
Expand Down Expand Up @@ -147,13 +146,13 @@ class AsyncEngine {
unsigned int jobIdCounter;

// Mutex to protect job queue
Mutex jobQueueMutex;
std::mutex jobQueueMutex;

// Job queue
std::deque<LuaJobInfo> jobQueue;

// Mutex to protect result queue
Mutex resultQueueMutex;
std::mutex resultQueueMutex;
// Result queue
std::deque<LuaJobInfo> resultQueue;

Expand Down

0 comments on commit d4c0f91

Please sign in to comment.