Cinnamon  1.0
chess engine
Mutex.h
Go to the documentation of this file.
00001 #ifndef MUTEX_H_
00002 #define MUTEX_H_
00003 
00004 #ifdef _WIN32
00005 #include <windows.h>
00006 
00007 class Mutex {
00008 public:
00009     Mutex() {
00010         mutex = CreateMutex(NULL,FALSE,NULL);
00011     }
00012 
00013     ~Mutex() {
00014         CloseHandle(mutex);
00015     }
00016 
00017     void lockMutex(bool b) {
00018         b ? WaitForSingleObject(mutex,INFINITE) : ReleaseMutex(mutex);
00019     }
00020 
00021 private:
00022     HANDLE mutex;
00023 };
00024 
00025 #else
00026 #include <pthread.h>
00027 
00028 class Mutex {
00029 public:
00030 
00031     Mutex() {
00032         mutex = PTHREAD_MUTEX_INITIALIZER;
00033     }
00034 
00035     ~Mutex() {
00036     }
00037 
00038     void lockMutex(bool b) {
00039         b ? pthread_mutex_lock(&mutex) : pthread_mutex_unlock(&mutex);
00040     }
00041 
00042 private:
00043     pthread_mutex_t mutex;
00044 };
00045 #endif
00046 
00047 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines