summaryrefslogtreecommitdiff
path: root/src/mutex.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-01-23 23:21:22 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-23 23:21:22 +0100
commit6f5a92dd172c5b0e424499b0c49cca90865859f6 (patch)
tree6f903181db4fe5f448cbd2e2eb718737f4533302 /src/mutex.cc
parent87c7bce04950b4901fd88343fb966f5ff30d4c0e (diff)
Possible fix to missing std::mutex in mingw.
Diffstat (limited to 'src/mutex.cc')
-rw-r--r--src/mutex.cc20
1 files changed, 10 insertions, 10 deletions
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 <windows.h>
#else
#include <pthread.h>
+#include <errno.h>
#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)
{