41 #ifndef _mezz_mutex_cpp
42 #define _mezz_mutex_cpp
56 #if defined(_MEZZ_THREAD_WIN32_)
57 : mAlreadyLocked(
false)
60 #if defined(_MEZZ_THREAD_WIN32_)
61 mHandle = (CRITICAL_SECTION*)( malloc(
sizeof(CRITICAL_SECTION) ) );
62 InitializeCriticalSection(mHandle);
64 pthread_mutex_init(&mHandle, NULL);
70 #if defined(_MEZZ_THREAD_WIN32_)
71 DeleteCriticalSection(mHandle);
74 pthread_mutex_destroy(&mHandle);
80 #if defined(_MEZZ_THREAD_WIN32_)
81 EnterCriticalSection(mHandle);
82 while(mAlreadyLocked) Sleep(100);
83 mAlreadyLocked =
true;
85 pthread_mutex_lock(&mHandle);
91 #if defined(_MEZZ_THREAD_WIN32_)
92 bool ret = (TryEnterCriticalSection(mHandle) ?
true :
false);
93 if(ret && mAlreadyLocked)
95 LeaveCriticalSection(mHandle);
100 return (pthread_mutex_trylock(&mHandle) == 0) ?
true :
false;
106 #if defined(_MEZZ_THREAD_WIN32_)
107 mAlreadyLocked =
false;
108 LeaveCriticalSection(mHandle);
110 pthread_mutex_unlock(&mHandle);
void Lock()
Lock the mutex.
Mutex()
Constructor, creates an unlocked mutex.
This file declares and defines a mutex that is a partial implementation.
bool TryLock()
Try to lock the mutex.
The bulk of the engine components go in this namspace.
void Unlock()
Unlock the mutex.