summaryrefslogtreecommitdiff
path: root/src/threading/mutex.h
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2016-10-06 21:13:04 +0200
committersfan5 <sfan5@live.de>2016-10-06 22:37:30 +0200
commit0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7 (patch)
treee51a3209f5d3215bd9ab55311b0e4702ce3e9fca /src/threading/mutex.h
parent155288ee981c70f505526347cb2bcda4df1c8e6b (diff)
downloadminetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.tar.gz
minetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.tar.bz2
minetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.zip
Fix C++11 Windows build of threading code
The initial problem was that mutex_auto_lock.h tries to use std::unique_lock<std::mutex> despite mutex.h not using C++11's std::mutex on Windows. The problem here is the mismatch between C++11 usage conditions of the two headers. This commit moves the decision logic to threads.h and makes sure mutex.h, mutex_auto_lock.h and event.h all use the same features.
Diffstat (limited to 'src/threading/mutex.h')
-rw-r--r--src/threading/mutex.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/threading/mutex.h b/src/threading/mutex.h
index dadbd050c..fb5c029fc 100644
--- a/src/threading/mutex.h
+++ b/src/threading/mutex.h
@@ -26,14 +26,15 @@ DEALINGS IN THE SOFTWARE.
#ifndef THREADING_MUTEX_H
#define THREADING_MUTEX_H
-// Windows std::mutex is much slower than the critical section API
-#if __cplusplus >= 201103L && !defined(_WIN32)
+#include "threads.h"
+
+#if USE_CPP11_MUTEX
#include <mutex>
using Mutex = std::mutex;
using RecursiveMutex = std::recursive_mutex;
#else
-#ifdef _WIN32
+#if USE_WIN_MUTEX
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
@@ -41,7 +42,7 @@ DEALINGS IN THE SOFTWARE.
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
-#else // pthread
+#else
#include <pthread.h>
#endif
@@ -59,9 +60,9 @@ protected:
Mutex(bool recursive);
void init_mutex(bool recursive);
private:
-#ifdef _WIN32
+#if USE_WIN_MUTEX
CRITICAL_SECTION mutex;
-#else // pthread
+#else
pthread_mutex_t mutex;
#endif
@@ -76,6 +77,6 @@ public:
DISABLE_CLASS_COPY(RecursiveMutex);
};
-#endif // C++11
+#endif // C++11
#endif