diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-09-20 16:08:52 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-09-20 16:08:52 +0200 |
commit | 5591f1602e6171492f5e4620e67d3addeacad7aa (patch) | |
tree | a51c16d5760cd7db9b1fbbf5bf3afeb9bae4ab18 /src/mutex.cc | |
parent | 6611e83df0ed5b9bed42ff8cd549da0b5df11df2 (diff) |
VSTi plugin version.
Diffstat (limited to 'src/mutex.cc')
-rw-r--r-- | src/mutex.cc | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/src/mutex.cc b/src/mutex.cc index ec0d0e8..22d59a6 100644 --- a/src/mutex.cc +++ b/src/mutex.cc @@ -27,32 +27,62 @@ */ #include "mutex.h" +#ifdef WIN32 +#include <windows.h> +#else +#include <pthread.h> +#endif + +struct mutex_private_t { +#ifdef WIN32 + HANDLE mutex; +#else + pthread_mutex_t mutex; +#endif +}; + Mutex::Mutex() { - pthread_mutex_init (&mutex, NULL); + prv = new struct mutex_private_t(); +#ifdef WIN32 + prv->mutex = CreateMutex(NULL, // default security attributes + FALSE, // initially not owned + NULL); // unnamed mutex +#else + pthread_mutex_init (&prv->mutex, NULL); +#endif } Mutex::~Mutex() { - pthread_mutex_destroy(&mutex); -} +#ifdef WIN32 + CloseHandle(prv->mutex); +#else + pthread_mutex_destroy(&prv->mutex); +#endif -bool Mutex::trylock() -{ - return pthread_mutex_trylock(&mutex) == 0; + if(prv) delete prv; } void Mutex::lock() { - pthread_mutex_lock(&mutex); +#ifdef WIN32 + WaitForSingleObject(prv->mutex, // handle to mutex + INFINITE); // no time-out interval +#else + pthread_mutex_lock(&prv->mutex); +#endif } void Mutex::unlock() { - pthread_mutex_unlock(&mutex); +#ifdef WIN32 + ReleaseMutex(prv->mutex); +#else + pthread_mutex_unlock(&prv->mutex); +#endif } - MutexAutolock::MutexAutolock(Mutex &m) : mutex(m) { |