3 changes: 1 addition & 2 deletions src/script/cpp_api/s_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -116,7 +115,7 @@ class ScriptApiBase {

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
Expand Down
4 changes: 2 additions & 2 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
Address m_bind_addr;

// Environment mutex (envlock)
Mutex m_env_mutex;
std::mutex m_env_mutex;

private:

Expand Down Expand Up @@ -578,7 +578,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// 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;
Expand Down
6 changes: 3 additions & 3 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -232,10 +232,10 @@ class Settings {

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;

};

Expand Down
2 changes: 1 addition & 1 deletion src/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class ShaderSource : public IWritableShaderSource
// 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;
Expand Down
1 change: 0 additions & 1 deletion src/threading/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
48 changes: 0 additions & 48 deletions src/threading/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 2 additions & 17 deletions src/threading/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
116 changes: 0 additions & 116 deletions src/threading/mutex.cpp

This file was deleted.

84 changes: 0 additions & 84 deletions src/threading/mutex.h

This file was deleted.

40 changes: 4 additions & 36 deletions src/threading/mutex_auto_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
6 changes: 3 additions & 3 deletions src/threading/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -153,8 +153,8 @@ class Thread {
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;
Expand Down
2 changes: 0 additions & 2 deletions src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
7 changes: 3 additions & 4 deletions src/util/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -117,7 +116,7 @@ class MutexedMap

private:
std::map<Key, Value> m_values;
mutable Mutex m_mutex;
mutable std::mutex m_mutex;
};


Expand Down Expand Up @@ -225,12 +224,12 @@ class MutexedQueue
}

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;
};

Expand Down
1 change: 0 additions & 1 deletion src/util/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions src/util/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,7 +50,7 @@ class MutexedVariable
// You pretty surely want to grab the lock when accessing this
T m_value;
private:
Mutex m_mutex;
std::mutex m_mutex;
};

/*
Expand Down