X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fmutex.h;h=b619fcdb7c6b9127a550a296c9f4cb521d0d3ecc;hp=0c2879e0cff6eb3301dd66c8c3c57faa3c1d0ba3;hb=727f8ce40806cc2f7c295260f3c9aa156c815c70;hpb=a883560b42163f5ed0c83204469d17dd4f0134b6 diff --git a/source/mutex.h b/source/mutex.h index 0c2879e..b619fcd 100644 --- a/source/mutex.h +++ b/source/mutex.h @@ -6,21 +6,29 @@ Distributed under the LGPL #ifndef MSP_FRAMEWORK_MUTEX_H_ #define MSP_FRAMEWORK_MUTEX_H_ -#include #include +#include "types.h" namespace Msp { class Mutex { public: +#ifndef WIN32 Mutex() { pthread_mutex_init(&mutex, 0); } int lock() { return pthread_mutex_lock(&mutex); } int trylock() { return pthread_mutex_trylock(&mutex); } int unlock() { return pthread_mutex_unlock(&mutex); } ~Mutex() { pthread_mutex_destroy(&mutex); } +#else + Mutex() { mutex=CreateMutex(0, false, 0); } + int lock() { return WaitForSingleObject(mutex, INFINITE)==WAIT_OBJECT_0; } + int trylock() { return WaitForSingleObject(mutex, 0)==WAIT_OBJECT_0; } + int unlock() { return !ReleaseMutex(mutex); } + ~Mutex() { CloseHandle(mutex); } +#endif private: - pthread_mutex_t mutex; + MutexHandle mutex; friend class Semaphore; };