#else
my_mutex=CreateMutex(NULL,FALSE,NULL);
#endif
- my_cur_thread=0;
- num_locks=0;
}
Mutex::~Mutex() {
}
void Mutex::Lock() {
- if (num_locks> 0) {
-#ifndef WIN32
- if (my_cur_thread==(pid_t) syscall(SYS_gettid)) {
-#else
- if (my_cur_thread==GetCurrentThreadId()) {
-#endif
- num_locks++;
- return;
- }
- }
#ifndef WIN32
pthread_mutex_lock(&my_mutex);
- my_cur_thread=syscall(SYS_gettid);
#else
WaitForSingleObject(my_mutex, INFINITE );
- my_cur_thread=GetCurrentThreadId();
#endif
- num_locks++;
-
}
void Mutex::Unlock() {
-#ifndef WIN32
- if (my_cur_thread==syscall(SYS_gettid)) num_locks--;
-#else
- if (my_cur_thread==GetCurrentThreadId()) num_locks--;
-#endif
- if (num_locks==0) {
- my_cur_thread=0;
#ifndef WIN32
pthread_mutex_unlock(&my_mutex);
#else
ReleaseMutex(my_mutex);
#endif
- }
}