#include "util/string.h"
#include "threading/thread.h"
-#include "threading/mutex.h"
#include "exceptions.h"
#include <map>
#include <string>
+#include <mutex>
class BanManager
{
bool isModified();
private:
- Mutex m_mutex;
+ std::mutex m_mutex;
std::string m_banfilepath;
StringMap m_ips;
bool m_modified;
#include "network/connection.h"
#include "clientenvironment.h"
#include "irrlichttypes_extrabloated.h"
-#include "threading/mutex.h"
#include <ostream>
#include <map>
#include <set>
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 {
// 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;
#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;
// 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;
#include <cstring>
#include <map>
#include <sstream>
-#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "config.h"
// 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()
{
#define EMERGE_HEADER
#include <map>
+#include <mutex>
#include "irr_v3d.h"
#include "util/container.h"
#include "mapgen.h" // for MapgenParams
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;
#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;
IGameDef *m_gamedef;
private:
- Mutex m_time_lock;
+ std::mutex m_time_lock;
DISABLE_CLASS_COPY(Environment);
};
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)
#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.
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
#include <list>
#include <map>
#include <errno.h>
+#include <mutex>
#include "threading/event.h"
#include "config.h"
#include "exceptions.h"
#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;
#include <queue>
#include <string>
#include <fstream>
+#include <mutex>
#include "threads.h"
#include "irrlichttypes.h"
// 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;
};
#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"
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;
#include "irrlichttypes_extrabloated.h"
#include "client.h"
#include "voxel.h"
-#include "threading/mutex.h"
#include "threading/semaphore.h"
#include <map>
#include <string>
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;
};
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;
};
#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); \
u16 m_oldest_non_answered_ack;
- Mutex m_list_mutex;
+ std::mutex m_list_mutex;
};
/*
// Key is seqnum
std::map<u16, IncomingSplitPacket*> m_buf;
- Mutex m_map_mutex;
+ std::mutex m_map_mutex;
};
struct OutgoingPacket
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;
bool IncUseCount();
void DecUseCount();
- Mutex m_exclusive_access_mutex;
+ std::mutex m_exclusive_access_mutex;
bool m_pending_deletion;
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;
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
#include "irrlichttypes_bloated.h"
#include "inventory.h"
-#include "threading/mutex.h"
#include <list>
+#include <mutex>
#define PLAYERNAME_SIZE 20
// Protect some critical areas
// hud for example can be modified by EmergeThread
// and ServerThread
- Mutex m_mutex;
+ std::mutex m_mutex;
};
#endif
#include <string>
#include <map>
-#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "util/timetaker.h"
#include "util/numeric.h" // paging()
}
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;
*/
#include "quicktune.h"
-#include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#include "util/string.h"
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();
}
}
#include <map>
#include "threading/thread.h"
-#include "threading/mutex.h"
#include "threading/semaphore.h"
#include "debug.h"
#include "lua.h"
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;
#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"
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
Address m_bind_addr;
// Environment mutex (envlock)
- Mutex m_env_mutex;
+ std::mutex m_env_mutex;
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;
#include "irrlichttypes_bloated.h"
#include "util/string.h"
-#include "threading/mutex.h"
#include <string>
#include <list>
#include <set>
+#include <mutex>
class Settings;
struct NoiseParams;
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;
};
// 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;
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)
#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
}
#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
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
+++ /dev/null
-/*
-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
-
+++ /dev/null
-/*
-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
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>;
#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
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;
#include <windows.h>
#endif
-#include "threading/mutex.h"
-
//
// threadid_t, threadhandle_t
//
#include "../irrlichttypes.h"
#include "../exceptions.h"
-#include "../threading/mutex.h"
#include "../threading/mutex_auto_lock.h"
#include "../threading/semaphore.h"
#include <list>
private:
std::map<Key, Value> m_values;
- mutable Mutex m_mutex;
+ mutable std::mutex m_mutex;
};
}
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;
};
#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))
#include "../irrlichttypes.h"
#include "../threading/thread.h"
-#include "../threading/mutex.h"
#include "../threading/mutex_auto_lock.h"
#include "porting.h"
#include "log.h"
// You pretty surely want to grab the lock when accessing this
T m_value;
private:
- Mutex m_mutex;
+ std::mutex m_mutex;
};
/*