#include <Synchronization.h>
Public Methods | |
Mutex () | |
Create a mutex. More... | |
~Mutex () | |
Destroy a mutex. More... | |
void | Wait () |
Wait on a mutex until it is available. More... | |
bool | TryWait () |
Try to wait on a mutex. More... | |
void | Release () |
Release the mutex. More... |
This is intended to be a cross-platform class; however, only the linux implementation has been used. Therefore the windows version probably doesn't actually work or compile so it needs to be worked on. This is a recursive mutex.
Definition at line 14 of file Synchronization.h.
|
Create a mutex. Creates a mutex that is not already held. Definition at line 19 of file Synchronization.cpp. References NULL.
00020 { 00021 #ifdef _WIN32 00022 m_mutex = CreateMutex(NULL, TRUE, NULL); 00023 if(m_mutex = NULL) 00024 { 00025 throw "Unable to create mutex"; 00026 } 00027 #endif 00028 #ifdef LINUX 00029 //m_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; 00030 pthread_mutexattr_t attr; 00031 pthread_mutexattr_init(&attr); 00032 attr.__mutexkind= PTHREAD_MUTEX_RECURSIVE_NP; 00033 // pthread_mutexattr_setkind(&attr, PTHREAD_MUTEX_RECURSIVE); 00034 pthread_mutex_init(&m_mutex, &attr); 00035 #endif 00036 } |
|
Destroy a mutex. Release all resources associated with this mutex. Definition at line 37 of file Synchronization.cpp.
00038 { 00039 #ifdef _WIN32 00040 CloseHandle(m_mutex); 00041 #endif 00042 #ifdef LINUX 00043 //while(pthread_mutex_destroy(&m_mutex) == EBUSY) 00044 // pthread_mutex_unlock(&m_mutex); 00045 #endif 00046 } |
|
Release the mutex. Unpredictable results occur when the mutex is not held before this call. |
|
Try to wait on a mutex. This returns immediately.
|
|
Wait on a mutex until it is available. This is a blocking call. If a different thread has the mutex, then this will wait until that thread releases. |