aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ban.h4
-rw-r--r--src/client.h1
-rw-r--r--src/client/clientlauncher.cpp2
-rw-r--r--src/client/tile.cpp2
-rw-r--r--src/clientiface.h6
-rw-r--r--src/debug.cpp3
-rw-r--r--src/emerge.h3
-rw-r--r--src/environment.h4
-rw-r--r--src/face_position_cache.cpp2
-rw-r--r--src/face_position_cache.h4
-rw-r--r--src/httpfetch.cpp3
-rw-r--r--src/log.h3
-rw-r--r--src/mesh_generator_thread.h3
-rw-r--r--src/minimap.h5
-rw-r--r--src/network/connection.cpp2
-rw-r--r--src/network/connection.h12
-rw-r--r--src/particles.h4
-rw-r--r--src/player.h4
-rw-r--r--src/profiler.h3
-rw-r--r--src/quicktune.cpp5
-rw-r--r--src/script/cpp_api/s_async.h5
-rw-r--r--src/script/cpp_api/s_base.h3
-rw-r--r--src/server.h4
-rw-r--r--src/settings.h6
-rw-r--r--src/shader.cpp2
-rw-r--r--src/threading/CMakeLists.txt1
-rw-r--r--src/threading/event.cpp48
-rw-r--r--src/threading/event.h19
-rw-r--r--src/threading/mutex.cpp116
-rw-r--r--src/threading/mutex.h84
-rw-r--r--src/threading/mutex_auto_lock.h40
-rw-r--r--src/threading/thread.h6
-rw-r--r--src/threads.h2
-rw-r--r--src/util/container.h7
-rw-r--r--src/util/numeric.h1
-rw-r--r--src/util/thread.h3
36 files changed, 59 insertions, 363 deletions
diff --git a/src/ban.h b/src/ban.h
index e35bd0e10..7c88406d4 100644
--- 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;
diff --git a/src/client.h b/src/client.h
index fc2416087..149fdfe57 100644
--- a/src/client.h
+++ b/src/client.h
@@ -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>
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 3e8fa2f2f..aeab82512 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -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 {
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index 0918836e5..10a9d5f0d 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -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;
diff --git a/src/clientiface.h b/src/clientiface.h
index 107ed3bf3..edcd91ef3 100644
--- a/src/clientiface.h
+++ b/src/clientiface.h
@@ -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;
diff --git a/src/debug.cpp b/src/debug.cpp
index 8647160b1..0490fcf4e 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -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()
{
diff --git a/src/emerge.h b/src/emerge.h
index 55be370d2..2b5d57434 100644
--- a/src/emerge.h
+++ b/src/emerge.h
@@ -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;
diff --git a/src/environment.h b/src/environment.h
index ff3942599..4c00ef9e8 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -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);
};
diff --git a/src/face_position_cache.cpp b/src/face_position_cache.cpp
index d2883a1b3..e6dd12170 100644
--- a/src/face_position_cache.cpp
+++ b/src/face_position_cache.cpp
@@ -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)
diff --git a/src/face_position_cache.h b/src/face_position_cache.h
index 5ea0d938b..29ae0f0a9 100644
--- a/src/face_position_cache.h
+++ b/src/face_position_cache.h
@@ -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
diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp
index 3b3f5d331..ac743bf77 100644
--- a/src/httpfetch.cpp
+++ b/src/httpfetch.cpp
@@ -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;
diff --git a/src/log.h b/src/log.h
index 219255d9a..c017d127e 100644
--- 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;
};
diff --git a/src/mesh_generator_thread.h b/src/mesh_generator_thread.h
index 6edb6906d..3ac086e30 100644
--- a/src/mesh_generator_thread.h
+++ b/src/mesh_generator_thread.h
@@ -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;
diff --git a/src/minimap.h b/src/minimap.h
index c50530335..58d05d668 100644
--- a/src/minimap.h
+++ b/src/minimap.h
@@ -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;
};
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index fb3ba92ae..61b98b6d7 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -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); \
diff --git a/src/network/connection.h b/src/network/connection.h
index 8b7ed9773..51cf6aec6 100644
--- a/src/network/connection.h
+++ b/src/network/connection.h
@@ -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;
diff --git a/src/particles.h b/src/particles.h
index eaec1f0fa..87583aae6 100644
--- a/src/particles.h
+++ b/src/particles.h
@@ -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
diff --git a/src/player.h b/src/player.h
index 3432069c0..00d27cb90 100644
--- a/src/player.h
+++ b/src/player.h
@@ -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
diff --git a/src/profiler.h b/src/profiler.h
index ce60c6262..2d70e8af4 100644
--- a/src/profiler.h
+++ b/src/profiler.h
@@ -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;
diff --git a/src/quicktune.cpp b/src/quicktune.cpp
index b0e2dc6d5..37d4933de 100644
--- a/src/quicktune.cpp
+++ b/src/quicktune.cpp
@@ -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();
}
}
diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h
index dbe0654e2..45f935d0a 100644
--- a/src/script/cpp_api/s_async.h
+++ b/src/script/cpp_api/s_async.h
@@ -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;
diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h
index 5b047a081..e0f6b23ae 100644
--- a/src/script/cpp_api/s_base.h
+++ b/src/script/cpp_api/s_base.h
@@ -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
diff --git a/src/server.h b/src/server.h
index 935be5f95..5236851fe 100644
--- a/src/server.h
+++ b/src/server.h
@@ -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;
diff --git a/src/settings.h b/src/settings.h
index e570c1a84..d1edca6b6 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -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;
};
diff --git a/src/shader.cpp b/src/shader.cpp
index 66f32c9a1..1d3f2f6a1 100644
--- a/src/shader.cpp
+++ b/src/shader.cpp
@@ -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;
diff --git a/src/threading/CMakeLists.txt b/src/threading/CMakeLists.txt
index 5dd60ef1a..8f86158be 100644
--- a/src/threading/CMakeLists.txt
+++ b/src/threading/CMakeLists.txt
@@ -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)
diff --git a/src/threading/event.cpp b/src/threading/event.cpp
index a22c6628b..4e8d4bb3e 100644
--- a/src/threading/event.cpp
+++ b/src/threading/event.cpp
@@ -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
}
diff --git a/src/threading/event.h b/src/threading/event.h
index 79a99ce1f..458864c82 100644
--- a/src/threading/event.h
+++ b/src/threading/event.h
@@ -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
index d864f12c5..000000000
--- a/src/threading/mutex.cpp
+++ /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
index 6feb23c25..000000000
--- a/src/threading/mutex.h
+++ /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
diff --git a/src/threading/mutex_auto_lock.h b/src/threading/mutex_auto_lock.h
index d79c68a93..c809ff8f5 100644
--- a/src/threading/mutex_auto_lock.h
+++ b/src/threading/mutex_auto_lock.h
@@ -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>;
diff --git a/src/threading/thread.h b/src/threading/thread.h
index 671a9be0b..ab943f094 100644
--- a/src/threading/thread.h
+++ b/src/threading/thread.h
@@ -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;
diff --git a/src/threads.h b/src/threads.h
index ce98593cd..9731dcb5e 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -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
//
diff --git a/src/util/container.h b/src/util/container.h
index 7f66b89ac..caaa1c328 100644
--- a/src/util/container.h
+++ b/src/util/container.h
@@ -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;
};
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 4a27f657d..3b1b85f64 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -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))
diff --git a/src/util/thread.h b/src/util/thread.h
index b96f302f6..201d09a08 100644
--- a/src/util/thread.h
+++ b/src/util/thread.h
@@ -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;
};
/*