From 6f5a92dd172c5b0e424499b0c49cca90865859f6 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 23 Jan 2016 23:21:22 +0100 Subject: Possible fix to missing std::mutex in mingw. --- src/mutex.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/mutex.cc') diff --git a/src/mutex.cc b/src/mutex.cc index 75c7dad..e01bc95 100644 --- a/src/mutex.cc +++ b/src/mutex.cc @@ -31,6 +31,7 @@ #include #else #include +#include #endif struct mutex_private_t { @@ -67,6 +68,15 @@ Mutex::~Mutex() } } +bool Mutex::try_lock() +{ +#ifdef WIN32 + return WaitForSingleObject(prv->mutex, 0) == WAIT_OBJECT_0; +#else + return pthread_mutex_trylock(&prv->mutex) != EBUSY; +#endif +} + void Mutex::lock() { #ifdef WIN32 @@ -86,16 +96,6 @@ void Mutex::unlock() #endif } -#ifdef WIN32 -// Hack: mingw doesn't have std::mutex -namespace std { -bool mutex::try_lock() -{ - return Mutex::trylock(); -} -} -#endif - MutexAutolock::MutexAutolock(Mutex &m) : mutex(m) { -- cgit v1.2.3