forked from Mirrorlandia_minetest/minetest
Use C++11 mutexes only (remove compat code) (#5922)
* Fix event LINT & remove default constructor/destructors * remove compat code & modernize autolock header
This commit is contained in:
parent
8bdde45895
commit
d4c0f91275
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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); \
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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>;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
//
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user