summaryrefslogtreecommitdiff
path: root/src/threading
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-01-23 05:45:00 +0100
committerest31 <MTest31@outlook.com>2016-01-23 05:45:29 +0100
commite50c784e2ca55735fc360ae51534288c2ea59ca5 (patch)
tree5460f36ef2e8a72ac629548f027956f055502bf1 /src/threading
parent0459eca8eb2e73e9670e00b838dabc9347acb35f (diff)
downloadminetest-e50c784e2ca55735fc360ae51534288c2ea59ca5.tar.gz
minetest-e50c784e2ca55735fc360ae51534288c2ea59ca5.tar.bz2
minetest-e50c784e2ca55735fc360ae51534288c2ea59ca5.zip
Fix C++11 compilability
Previous commits broke it... :(
Diffstat (limited to 'src/threading')
-rw-r--r--src/threading/event.h1
-rw-r--r--src/threading/mutex.cpp15
-rw-r--r--src/threading/mutex.h14
-rw-r--r--src/threading/mutex_auto_lock.h12
4 files changed, 40 insertions, 2 deletions
diff --git a/src/threading/event.h b/src/threading/event.h
index dba3ddb4c..43f2b04be 100644
--- a/src/threading/event.h
+++ b/src/threading/event.h
@@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L
#include <condition_variable>
#include "threading/mutex.h"
+ #include "threading/mutex_auto_lock.h"
#elif defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
diff --git a/src/threading/mutex.cpp b/src/threading/mutex.cpp
index e12b79185..f2b07bec3 100644
--- a/src/threading/mutex.cpp
+++ b/src/threading/mutex.cpp
@@ -34,8 +34,19 @@ DEALINGS IN THE SOFTWARE.
#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)
+{
#ifdef _WIN32
// Windows critical sections are recursive by default
UNUSED(recursive);
@@ -89,5 +100,9 @@ void Mutex::unlock()
#endif
}
+RecursiveMutex::RecursiveMutex()
+ : Mutex(true)
+{}
+
#endif
diff --git a/src/threading/mutex.h b/src/threading/mutex.h
index 40b10a2ea..dadbd050c 100644
--- a/src/threading/mutex.h
+++ b/src/threading/mutex.h
@@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L && !defined(_WIN32)
#include <mutex>
using Mutex = std::mutex;
+ using RecursiveMutex = std::recursive_mutex;
#else
#ifdef _WIN32
@@ -49,11 +50,14 @@ DEALINGS IN THE SOFTWARE.
class Mutex
{
public:
- Mutex(bool recursive=false);
+ Mutex();
~Mutex();
void lock();
void unlock();
+protected:
+ Mutex(bool recursive);
+ void init_mutex(bool recursive);
private:
#ifdef _WIN32
CRITICAL_SECTION mutex;
@@ -64,6 +68,14 @@ private:
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 1c39349e5..25caf7e14 100644
--- a/src/threading/mutex_auto_lock.h
+++ b/src/threading/mutex_auto_lock.h
@@ -28,7 +28,8 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L
#include <mutex>
- using MutexAutoLock = std::lock_guard<std::mutex>;
+ using MutexAutoLock = std::unique_lock<std::mutex>;
+ using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;
#else
#include "threading/mutex.h"
@@ -44,6 +45,15 @@ private:
Mutex &mutex;
};
+class RecursiveMutexAutoLock
+{
+public:
+ RecursiveMutexAutoLock(RecursiveMutex &m) : mutex(m) { mutex.lock(); }
+ ~RecursiveMutexAutoLock() { mutex.unlock(); }
+
+private:
+ RecursiveMutex &mutex;
+};
#endif
#endif