00001
00002
00003 #ifdef WIN32
00004 # include <windows.h>
00005 #endif
00006
00007 #include "CCSThreadMutex.h"
00008
00009 using MSP::CCSThreadMutex;
00010
00011 CCSThreadMutex::CCSThreadMutex()
00012 {
00013 #ifdef WIN32
00014 mutex = (void*)CreateMutex(NULL,FALSE,NULL);
00015 #else
00016
00017 pthread_mutexattr_t attr;
00018 pthread_mutexattr_init(&attr);
00019 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
00020 pthread_mutex_init(&mutex, &attr);
00021 pthread_mutexattr_destroy(&attr);
00022 #endif
00023 }
00024
00025 CCSThreadMutex::~CCSThreadMutex()
00026 {
00027 #ifdef WIN32
00028 CloseHandle((HANDLE)mutex);
00029 #else
00030
00031 pthread_mutex_destroy(&mutex);
00032 #endif
00033 }
00034 void
00035 CCSThreadMutex::lock() const
00036 {
00037 #ifdef WIN32
00038 WaitForSingleObject((HANDLE)mutex, INFINITE);
00039 #else
00040
00041 pthread_mutex_lock(&mutex);
00042 #endif
00043 }
00044
00045
00046 void
00047 CCSThreadMutex::unlock() const
00048 {
00049 #ifdef WIN32
00050 ReleaseMutex((HANDLE)mutex);
00051 #else
00052
00053 pthread_mutex_unlock(&mutex);
00054 #endif
00055 }
00056
00057