21#include "wlib/wdebug.h"
31 InitializeCriticalSection(&CritSec_);
38 pthread_mutex_destroy(&
Mutex_);
40 DeleteCriticalSection(&CritSec_);
60 if (((status = pthread_mutex_trylock(&Mutex_)) == 0) ||
61 ((status == EBUSY) && (ThreadId_ == pthread_self())))
63 ThreadId_ = pthread_self();
71 if ((status = pthread_mutex_lock(&Mutex_)) == 0)
73 assert(RefCount_ == 0);
74 ThreadId_ = pthread_self();
79 ERRMSG(
"pthread_mutex_lock: " << strerror(errno));
88 EnterCriticalSection(&CritSec_);
91 #error Must define either _WIN32 or _UNIX
101 assert(RefCount_ >= 0);
109 if (ThreadId_ != pthread_self())
111 WRNMSG(
"tried to unlock a mutex not owned by self");
115 if (--RefCount_ == 0)
118 ThreadId_ = (pthread_t)0;
121 if ((status = pthread_mutex_unlock(&Mutex_)) != 0)
122 ERRMSG(
"pthread_mutex_lock: " << strerror(errno));
125 #elif defined(_WIN32)
126 LeaveCriticalSection(&CritSec_);
sint32 lock(int *refcount=NULL) RO