summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mutex.cc20
-rw-r--r--src/mutex.h8
2 files changed, 12 insertions, 16 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)
{
diff --git a/src/mutex.h b/src/mutex.h
index 8c71733..4659a07 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -34,7 +34,7 @@ public:
Mutex();
~Mutex();
- bool trylock();
+ bool try_lock();
void lock();
void unlock();
@@ -45,11 +45,7 @@ private:
#ifdef WIN32
// Hack: mingw doesn't have std::mutex
namespace std {
-class mutex
- : public Mutex {
-public:
- bool try_lock();
-};
+ class mutex : public Mutex {};
}
#endif