diff options
author | sfan5 <sfan5@live.de> | 2016-10-06 21:13:04 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2016-10-06 22:37:30 +0200 |
commit | 0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7 (patch) | |
tree | e51a3209f5d3215bd9ab55311b0e4702ce3e9fca /src/threading/mutex.cpp | |
parent | 155288ee981c70f505526347cb2bcda4df1c8e6b (diff) | |
download | minetest-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.cpp')
-rw-r--r-- | src/threading/mutex.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/threading/mutex.cpp b/src/threading/mutex.cpp index f2b07bec3..0908b5d37 100644 --- a/src/threading/mutex.cpp +++ b/src/threading/mutex.cpp @@ -23,14 +23,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Windows std::mutex is much slower than the critical section API -#if __cplusplus < 201103L || defined(_WIN32) +#include "threads.h" + +#ifndef USE_CPP11_MUTEX #include "threading/mutex.h" -#ifndef _WIN32 - #include <cassert> -#endif +#include <cassert> #define UNUSED(expr) do { (void)(expr); } while (0) @@ -47,7 +46,7 @@ Mutex::Mutex(bool recursive) void Mutex::init_mutex(bool recursive) { -#ifdef _WIN32 +#if USE_WIN_MUTEX // Windows critical sections are recursive by default UNUSED(recursive); @@ -69,7 +68,7 @@ void Mutex::init_mutex(bool recursive) Mutex::~Mutex() { -#ifdef _WIN32 +#if USE_WIN_MUTEX DeleteCriticalSection(&mutex); #else int ret = pthread_mutex_destroy(&mutex); @@ -80,7 +79,7 @@ Mutex::~Mutex() void Mutex::lock() { -#ifdef _WIN32 +#if USE_WIN_MUTEX EnterCriticalSection(&mutex); #else int ret = pthread_mutex_lock(&mutex); @@ -91,7 +90,7 @@ void Mutex::lock() void Mutex::unlock() { -#ifdef _WIN32 +#if USE_WIN_MUTEX LeaveCriticalSection(&mutex); #else int ret = pthread_mutex_unlock(&mutex); @@ -104,5 +103,5 @@ RecursiveMutex::RecursiveMutex() : Mutex(true) {} -#endif +#endif // C++11 |