1
0
Fork 0
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:
sfan5 2016-10-06 21:13:04 +02:00
parent 155288ee98
commit 0a16e53b40
8 changed files with 65 additions and 57 deletions

View file

@ -26,17 +26,12 @@ DEALINGS IN THE SOFTWARE.
#ifndef THREADING_EVENT_H
#define THREADING_EVENT_H
#if __cplusplus >= 201103L
#include "threads.h"
#if USE_CPP11_MUTEX
#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
#endif
#include <windows.h>
#else
#include <pthread.h>
#endif
@ -49,18 +44,18 @@ DEALINGS IN THE SOFTWARE.
class Event {
public:
Event();
#if __cplusplus < 201103L
#ifndef USE_CPP11_MUTEX
~Event();
#endif
void wait();
void signal();
private:
#if __cplusplus >= 201103L
#if USE_CPP11_MUTEX
std::condition_variable cv;
Mutex mutex;
bool notified;
#elif defined(_WIN32)
#elif USE_WIN_MUTEX
HANDLE event;
#else
pthread_cond_t cv;