mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
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.
This commit is contained in:
parent
155288ee98
commit
0a16e53b40
8 changed files with 65 additions and 57 deletions
|
@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define THREADS_HEADER
|
||||
|
||||
//
|
||||
// Determine which threading API we will use
|
||||
// Determine which threading APIs we will use
|
||||
//
|
||||
#if __cplusplus >= 201103L
|
||||
#define USE_CPP11_THREADS 1
|
||||
|
@ -31,11 +31,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define USE_POSIX_THREADS 1
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Prefer critical section API because std::mutex is much slower on Windows
|
||||
#define USE_WIN_MUTEX 1
|
||||
#elif __cplusplus >= 201103L
|
||||
#define USE_CPP11_MUTEX 1
|
||||
#else
|
||||
#define USE_POSIX_MUTEX 1
|
||||
#endif
|
||||
|
||||
///////////////
|
||||
|
||||
|
||||
#if USE_CPP11_THREADS
|
||||
#include <thread>
|
||||
#elif USE_POSIX_THREADS
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "threading/mutex.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue