Use C++11 mutexes only (remove compat code) (#5922)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 6 Jun 2017 14:29:28 +0000 (16:29 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Jun 2017 14:29:28 +0000 (16:29 +0200)
* Fix event LINT & remove default constructor/destructors
* remove compat code & modernize autolock header

36 files changed:
src/ban.h
src/client.h
src/client/clientlauncher.cpp
src/client/tile.cpp
src/clientiface.h
src/debug.cpp
src/emerge.h
src/environment.h
src/face_position_cache.cpp
src/face_position_cache.h
src/httpfetch.cpp
src/log.h
src/mesh_generator_thread.h
src/minimap.h
src/network/connection.cpp
src/network/connection.h
src/particles.h
src/player.h
src/profiler.h
src/quicktune.cpp
src/script/cpp_api/s_async.h
src/script/cpp_api/s_base.h
src/server.h
src/settings.h
src/shader.cpp
src/threading/CMakeLists.txt
src/threading/event.cpp
src/threading/event.h
src/threading/mutex.cpp [deleted file]
src/threading/mutex.h [deleted file]
src/threading/mutex_auto_lock.h
src/threading/thread.h
src/threads.h
src/util/container.h
src/util/numeric.h
src/util/thread.h

index e35bd0e10e2dc135f3967eceff9ea72dccb80063..7c88406d48e79462f13380ffc9a22c610738b4c3 100644 (file)
--- a/src/ban.h
+++ b/src/ban.h
@@ -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
 {
@@ -43,7 +43,7 @@ public:
        bool isModified();
 
 private:
-       Mutex m_mutex;
+       std::mutex m_mutex;
        std::string m_banfilepath;
        StringMap m_ips;
        bool m_modified;
index fc24160874d0a6914719aac0ccb62949f5d5f334..149fdfe57705e3d40c4a84d60adac1e7a63abbbf 100644 (file)
@@ -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>
index 3e8fa2f2ff8ce086942cf003afd6d7964f097ab9..aeab825126a2de1e7a0ddb8f9b7b9e81a3a31603 100644 (file)
@@ -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 {
index 0918836e5de573142b1b7f738d5c5b2a69fcc9ea..10a9d5f0d23cc3f2ca9c4740b2c0d37fdd2aa2b4 100644 (file)
@@ -417,7 +417,7 @@ private:
        // 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;
index 107ed3bf30ba18a632b51633bcb4f8b65ac29d49..edcd91ef3010ba26e99fac821afc5b1ae9217bd0 100644 (file)
@@ -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;
@@ -508,14 +508,14 @@ private:
 
        // 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;
 
index 8647160b1bed7c20cae3dae6e035bfc23bef521e..0490fcf4e095022478be6d8ab8d72a67555fb9a4 100644 (file)
@@ -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"
 
@@ -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()
 {
index 55be370d21dd542b47ea4c6cf5e6fa1c66932ff5..2b5d5743462318a5361708333c54c2600eff4795 100644 (file)
@@ -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
@@ -155,7 +156,7 @@ private:
        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;
 
index ff3942599a34f0f0ff7bfd8dba91f1978ec4fad1..4c00ef9e85890c9b83c8d743db02c5ddec3512cf 100644 (file)
@@ -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;
@@ -120,7 +120,7 @@ protected:
        IGameDef *m_gamedef;
 
 private:
-       Mutex m_time_lock;
+       std::mutex m_time_lock;
 
        DISABLE_CLASS_COPY(Environment);
 };
index d2883a1b33d001f9a91299283625e18fba3fada0..e6dd12170f8019ebaca8a8ee1e15752e2932ab1d 100644 (file)
@@ -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)
index 5ea0d938b2e1c778cc0cc312942e830d825f83d5..29ae0f0a98ad99ce8c23c7becd1c5505657c6f80 100644 (file)
@@ -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.
@@ -38,7 +38,7 @@ public:
 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
index 3b3f5d33126d11a0da4b84132f14cfa1802c1fcd..ac743bf77fe9df6a7655e6963dead682b7c5d3c8 100644 (file)
@@ -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"
@@ -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;
 
index 219255d9abfd6af92f042efa32ea0df3946d56e2..c017d127e6c21d9305c3c545b728117fa3e8d3ed 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -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"
 
@@ -79,7 +80,7 @@ private:
        // 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;
 };
 
index 6edb6906d9712c92f4326fce70474ebaf38702e0..3ac086e30be40ff1ffc91b4034034bf0c880056b 100644 (file)
@@ -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"
@@ -83,7 +84,7 @@ private:
        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;
index c50530335082bcf80c45be4130af51b88e7d860f..58d05d6680ee65ca4b41356098bc184b8413d515 100644 (file)
@@ -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>
@@ -112,7 +111,7 @@ protected:
        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;
 };
@@ -161,7 +160,7 @@ private:
        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;
 };
 
index fb3ba92aefd16495fa9275c51ef0de0c701e783e..61b98b6d743bace3ab49f0698e9b93c817beca1d 100644 (file)
@@ -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);                                 \
index 8b7ed9773a9c016c663ada03c01a3260245d533f..51cf6aec63640c3c71e108356f906897582ac978 100644 (file)
@@ -349,7 +349,7 @@ private:
 
        u16 m_oldest_non_answered_ack;
 
-       Mutex m_list_mutex;
+       std::mutex m_list_mutex;
 };
 
 /*
@@ -372,7 +372,7 @@ private:
        // Key is seqnum
        std::map<u16, IncomingSplitPacket*> m_buf;
 
-       Mutex m_map_mutex;
+       std::mutex m_map_mutex;
 };
 
 struct OutgoingPacket
@@ -544,7 +544,7 @@ public:
 
        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;
@@ -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;
 
@@ -1064,12 +1064,12 @@ private:
 
        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;
index eaec1f0fa784a4d942bc973875f9d24c10e7e1c5..87583aae6a260e479c647bbda3f57d7a3f30538c 100644 (file)
@@ -213,8 +213,8 @@ private:
        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
index 3432069c0524a70e297b6befe85b689669d5ec02..00d27cb90e98f822c719b13a7595b60b31baeb3e 100644 (file)
@@ -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
 
@@ -186,7 +186,7 @@ private:
        // Protect some critical areas
        // hud for example can be modified by EmergeThread
        // and ServerThread
-       Mutex m_mutex;
+       std::mutex m_mutex;
 };
 
 #endif
index ce60c6262d15f296adf1d410b37b1672c3fbe1a3..2d70e8af4fb3efc058c49878b32221234e14b3c5 100644 (file)
@@ -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()
@@ -177,7 +176,7 @@ public:
        }
 
 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;
index b0e2dc6d5bbd731889f488ce1960ba761dc42b04..37d4933de5605b0a69b37839250ff6219da1432d 100644 (file)
@@ -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"
 
@@ -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();
        }
 }
 
index dbe0654e280282949b517d66777ef6f102338596..45f935d0a20ed1cdd5c15463e93e224b97bfd4a2 100644 (file)
@@ -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"
@@ -147,13 +146,13 @@ private:
        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;
 
index 5b047a08113fc9cadeb9430efef83935a209f699..e0f6b23aeb05ac60f4b49c4589e622038a015b4f 100644 (file)
@@ -29,7 +29,6 @@ extern "C" {
 
 #include "irrlichttypes.h"
 #include "threads.h"
-#include "threading/mutex.h"
 #include "threading/mutex_auto_lock.h"
 #include "common/c_types.h"
 #include "common/c_internal.h"
@@ -116,7 +115,7 @@ protected:
 
        void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
 
-       RecursiveMutex  m_luastackmutex;
+       std::recursive_mutex m_luastackmutex;
        std::string     m_last_run_mod;
        bool            m_secure;
 #ifdef SCRIPTAPI_LOCK_DEBUG
index 935be5f957104531c02f9cb1e3c822ee34397e18..5236851fe2578d680ca174c19f6a3ebf1e870c1b 100644 (file)
@@ -375,7 +375,7 @@ public:
        Address m_bind_addr;
 
        // Environment mutex (envlock)
-       Mutex m_env_mutex;
+       std::mutex m_env_mutex;
 
 private:
 
@@ -578,7 +578,7 @@ private:
        // A buffer for time steps
        // step() increments and AsyncRunStep() run by m_thread reads it.
        float m_step_dtime;
-       Mutex m_step_dtime_mutex;
+       std::mutex m_step_dtime_mutex;
 
        // current server step lag counter
        float m_lag;
index e570c1a84930d8256924cbc1d482048393587623..d1edca6b6239589ef18ad7698c4bdbcc005069c0 100644 (file)
@@ -22,10 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "irrlichttypes_bloated.h"
 #include "util/string.h"
-#include "threading/mutex.h"
 #include <string>
 #include <list>
 #include <set>
+#include <mutex>
 
 class Settings;
 struct NoiseParams;
@@ -232,10 +232,10 @@ private:
 
        SettingsCallbackMap m_callbacks;
 
-       mutable Mutex m_callback_mutex;
+       mutable std::mutex m_callback_mutex;
 
        // All methods that access m_settings/m_defaults directly should lock this.
-       mutable Mutex m_mutex;
+       mutable std::mutex m_mutex;
 
 };
 
index 66f32c9a1846bc6e6439f63829841bbc72306698..1d3f2f6a1bb524e6c132838657ee016ffeff4416 100644 (file)
@@ -320,7 +320,7 @@ private:
        // The first position contains a dummy shader.
        std::vector<ShaderInfo> m_shaderinfo_cache;
        // The former container is behind this mutex
-       Mutex m_shaderinfo_cache_mutex;
+       std::mutex m_shaderinfo_cache_mutex;
 
        // Queued shader fetches (to be processed by the main thread)
        RequestQueue<std::string, u32, u8, u8> m_get_shader_queue;
index 5dd60ef1a4dc424e6ef2176fd362e3b14634362e..8f86158be5eb7e210b32a1fff709abe0d746230e 100644 (file)
@@ -1,6 +1,5 @@
 set(JTHREAD_SRCS
        ${CMAKE_CURRENT_SOURCE_DIR}/event.cpp
-       ${CMAKE_CURRENT_SOURCE_DIR}/mutex.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/semaphore.cpp
        PARENT_SCOPE)
index a22c6628b965086d6b9c2df26e5e05e7f91452d5..4e8d4bb3e8a927b20663222bf4db8526b9e16432 100644 (file)
@@ -25,67 +25,19 @@ DEALINGS IN THE SOFTWARE.
 
 #include "threading/event.h"
 
-Event::Event()
-{
-#ifndef USE_CPP11_MUTEX
-#      if USE_WIN_MUTEX
-       event = CreateEvent(NULL, false, false, NULL);
-#      else
-       pthread_cond_init(&cv, NULL);
-       pthread_mutex_init(&mutex, NULL);
-       notified = false;
-#      endif
-#elif USE_CPP11_MUTEX
-       notified = false;
-#endif
-}
-
-#ifndef USE_CPP11_MUTEX
-Event::~Event()
-{
-#if USE_WIN_MUTEX
-       CloseHandle(event);
-#else
-       pthread_cond_destroy(&cv);
-       pthread_mutex_destroy(&mutex);
-#endif
-}
-#endif
-
-
 void Event::wait()
 {
-#if USE_CPP11_MUTEX
        MutexAutoLock lock(mutex);
        while (!notified) {
                cv.wait(lock);
        }
        notified = false;
-#elif USE_WIN_MUTEX
-       WaitForSingleObject(event, INFINITE);
-#else
-       pthread_mutex_lock(&mutex);
-       while (!notified) {
-               pthread_cond_wait(&cv, &mutex);
-       }
-       notified = false;
-       pthread_mutex_unlock(&mutex);
-#endif
 }
 
 
 void Event::signal()
 {
-#if USE_CPP11_MUTEX
        MutexAutoLock lock(mutex);
        notified = true;
        cv.notify_one();
-#elif USE_WIN_MUTEX
-       SetEvent(event);
-#else
-       pthread_mutex_lock(&mutex);
-       notified = true;
-       pthread_cond_signal(&cv);
-       pthread_mutex_unlock(&mutex);
-#endif
 }
index 79a99ce1fe28b436a0739b575636cf6c78f8363c..458864c8204bbc5cefa05876b7cbe32fcb90b81b 100644 (file)
@@ -28,11 +28,8 @@ DEALINGS IN THE SOFTWARE.
 
 #include "threads.h"
 
-#if USE_CPP11_MUTEX
 #include <condition_variable>
-#include "threading/mutex.h"
 #include "threading/mutex_auto_lock.h"
-#endif
 
 /** A syncronization primitive that will wake up one waiting thread when signaled.
  * Calling @c signal() multiple times before a waiting thread has had a chance
@@ -43,25 +40,13 @@ DEALINGS IN THE SOFTWARE.
 class Event
 {
 public:
-       Event();
-#ifndef USE_CPP11_MUTEX
-       ~Event();
-#endif
        void wait();
        void signal();
 
 private:
-#if USE_CPP11_MUTEX
        std::condition_variable cv;
-       Mutex mutex;
-       bool notified;
-#elif USE_WIN_MUTEX
-       HANDLE event;
-#else
-       pthread_cond_t cv;
-       pthread_mutex_t mutex;
-       bool notified;
-#endif
+       std::mutex mutex;
+       bool notified = false;
 };
 
 #endif
diff --git a/src/threading/mutex.cpp b/src/threading/mutex.cpp
deleted file mode 100644 (file)
index d864f12..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
-This file is a part of the JThread package, which contains some object-
-oriented thread wrappers for different thread implementations.
-
-Copyright (c) 2000-2006  Jori Liesenborgs (jori.liesenborgs@gmail.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-#include "threads.h"
-
-#ifndef USE_CPP11_MUTEX
-
-#include "threading/mutex.h"
-
-#include <cassert>
-
-#define UNUSED(expr) do { (void)(expr); } while (0)
-
-Mutex::Mutex()
-{
-       init_mutex(false);
-}
-
-
-Mutex::Mutex(bool recursive)
-{
-       init_mutex(recursive);
-}
-
-void Mutex::init_mutex(bool recursive)
-{
-#if USE_WIN_MUTEX
-       // Windows critical sections are recursive by default
-       UNUSED(recursive);
-
-       InitializeCriticalSection(&mutex);
-#else
-       pthread_mutexattr_t attr;
-       pthread_mutexattr_init(&attr);
-
-       if (recursive)
-               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-
-       int ret = pthread_mutex_init(&mutex, &attr);
-       assert(!ret);
-       UNUSED(ret);
-
-       pthread_mutexattr_destroy(&attr);
-#endif
-}
-
-Mutex::~Mutex()
-{
-#if USE_WIN_MUTEX
-       DeleteCriticalSection(&mutex);
-#else
-       int ret = pthread_mutex_destroy(&mutex);
-       assert(!ret);
-       UNUSED(ret);
-#endif
-}
-
-void Mutex::lock()
-{
-#if USE_WIN_MUTEX
-       EnterCriticalSection(&mutex);
-#else
-       int ret = pthread_mutex_lock(&mutex);
-       assert(!ret);
-       UNUSED(ret);
-#endif
-}
-
-bool Mutex::try_lock()
-{
-#if USE_WIN_MUTEX
-       return TryEnterCriticalSection(&mutex) != 0;
-#else
-       return pthread_mutex_trylock(&mutex) == 0;
-#endif
-}
-
-void Mutex::unlock()
-{
-#if USE_WIN_MUTEX
-       LeaveCriticalSection(&mutex);
-#else
-       int ret = pthread_mutex_unlock(&mutex);
-       assert(!ret);
-       UNUSED(ret);
-#endif
-}
-
-RecursiveMutex::RecursiveMutex()
-       : Mutex(true)
-{}
-
-#endif // C++11
-
diff --git a/src/threading/mutex.h b/src/threading/mutex.h
deleted file mode 100644 (file)
index 6feb23c..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-This file is a part of the JThread package, which contains some object-
-oriented thread wrappers for different thread implementations.
-
-Copyright (c) 2000-2006  Jori Liesenborgs (jori.liesenborgs@gmail.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef THREADING_MUTEX_H
-#define THREADING_MUTEX_H
-
-#include "threads.h"
-
-#if USE_CPP11_MUTEX
-       #include <mutex>
-       using Mutex = std::mutex;
-       using RecursiveMutex = std::recursive_mutex;
-#else
-
-#if USE_WIN_MUTEX
-       #ifndef _WIN32_WINNT
-               #define _WIN32_WINNT 0x0501
-       #endif
-       #ifndef WIN32_LEAN_AND_MEAN
-               #define WIN32_LEAN_AND_MEAN
-       #endif
-       #include <windows.h>
-#else
-       #include <pthread.h>
-#endif
-
-#include "util/basic_macros.h"
-
-class Mutex
-{
-public:
-       Mutex();
-       ~Mutex();
-       void lock();
-       void unlock();
-
-       bool try_lock();
-
-protected:
-       Mutex(bool recursive);
-       void init_mutex(bool recursive);
-private:
-#if USE_WIN_MUTEX
-       CRITICAL_SECTION mutex;
-#else
-       pthread_mutex_t mutex;
-#endif
-
-       DISABLE_CLASS_COPY(Mutex);
-};
-
-class RecursiveMutex : public Mutex
-{
-public:
-       RecursiveMutex();
-
-       DISABLE_CLASS_COPY(RecursiveMutex);
-};
-
-#endif // C++11
-
-#endif
index d79c68a939f7586741fe64d1c91aa9e27d90a4e4..c809ff8f5856e0d15cce1c65f7f00edbf8dad7b3 100644 (file)
@@ -23,40 +23,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef THREADING_MUTEX_AUTO_LOCK_H
-#define THREADING_MUTEX_AUTO_LOCK_H
-
-#include "threads.h"
-
-#if USE_CPP11_MUTEX
-       #include <mutex>
-       using MutexAutoLock = std::unique_lock<std::mutex>;
-       using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;
-#else
-
-#include "threading/mutex.h"
-
-
-class MutexAutoLock
-{
-public:
-       MutexAutoLock(Mutex &m) : mutex(m) { mutex.lock(); }
-       ~MutexAutoLock() { mutex.unlock(); }
-
-private:
-       Mutex &mutex;
-};
-
-class RecursiveMutexAutoLock
-{
-public:
-       RecursiveMutexAutoLock(RecursiveMutex &m) : mutex(m) { mutex.lock(); }
-       ~RecursiveMutexAutoLock() { mutex.unlock(); }
-
-private:
-       RecursiveMutex &mutex;
-};
-#endif
-
-#endif
+#pragma once
 
+#include <mutex>
+using MutexAutoLock = std::unique_lock<std::mutex>;
+using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;
index 671a9be0b973eb8ddc8e2b163b8d4e43523f2545..ab943f0940be176d32752d6cb121d9256a6b63c8 100644 (file)
@@ -27,11 +27,11 @@ DEALINGS IN THE SOFTWARE.
 #define THREADING_THREAD_H
 
 #include "util/basic_macros.h"
-#include "threading/mutex.h"
 #include "threads.h"
 
 #include <string>
 #include <atomic>
+#include <mutex>
 
 #ifdef _AIX
        #include <sys/thread.h> // for tid_t
@@ -153,8 +153,8 @@ private:
        bool m_joinable;
        std::atomic<bool> m_request_stop;
        std::atomic<bool> m_running;
-       Mutex m_mutex;
-       Mutex m_start_finished_mutex;
+       std::mutex m_mutex;
+       std::mutex m_start_finished_mutex;
 
 #if USE_CPP11_THREADS
        std::thread *m_thread_obj;
index ce98593cd2771501bd274d6e4fc851906e2ca0ab..9731dcb5e18bdb38f4ac2f8f6536ae786ea6109f 100644 (file)
@@ -54,8 +54,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #include <windows.h>
 #endif
 
-#include "threading/mutex.h"
-
 //
 // threadid_t, threadhandle_t
 //
index 7f66b89ac303531ea1fe20f2733498280624bc2e..caaa1c328fdd32bb10c319c802770b82722970c1 100644 (file)
@@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "../irrlichttypes.h"
 #include "../exceptions.h"
-#include "../threading/mutex.h"
 #include "../threading/mutex_auto_lock.h"
 #include "../threading/semaphore.h"
 #include <list>
@@ -117,7 +116,7 @@ public:
 
 private:
        std::map<Key, Value> m_values;
-       mutable Mutex m_mutex;
+       mutable std::mutex m_mutex;
 };
 
 
@@ -225,12 +224,12 @@ public:
        }
 
 protected:
-       Mutex &getMutex() { return m_mutex; }
+       std::mutex &getMutex() { return m_mutex; }
 
        std::deque<T> &getQueue() { return m_queue; }
 
        std::deque<T> m_queue;
-       mutable Mutex m_mutex;
+       mutable std::mutex m_mutex;
        Semaphore m_signal;
 };
 
index 4a27f657d23faab74a8a82d584f97c278b4906fc..3b1b85f64640adf4b1be8fb18db683908a1e1508 100644 (file)
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "../irr_v2d.h"
 #include "../irr_v3d.h"
 #include "../irr_aabb3d.h"
-#include "../threading/mutex.h"
 
 #define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d)))
 #define myfloor(x) ((x) < 0.0 ? (int)(x) - 1 : (int)(x))
index b96f302f6e9281bee5a01e6ea236c56e1476dba2..201d09a08c1110249dd2fbb389f704e843c07916 100644 (file)
@@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "../irrlichttypes.h"
 #include "../threading/thread.h"
-#include "../threading/mutex.h"
 #include "../threading/mutex_auto_lock.h"
 #include "porting.h"
 #include "log.h"
@@ -51,7 +50,7 @@ public:
        // You pretty surely want to grab the lock when accessing this
        T m_value;
 private:
-       Mutex m_mutex;
+       std::mutex m_mutex;
 };
 
 /*