TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::GMutex Class Reference

Mutual exclusion lock used for synchronization. More...

#include <GMutex.h>

Public Member Functions

 GMutex ()
 
 ~GMutex ()
 
void lock ()
 
bool tryLock ()
 
void unlock ()
 

Private Member Functions

 GMutex (const GMutex &mlock)
 
GMutexoperator= (const GMutex &)
 
bool operator== (const GMutex &)
 

Private Attributes

pthread_mutex_t m_handle
 
pthread_mutexattr_t m_attr
 

Detailed Description

Mutual exclusion lock used for synchronization.

See also
G3D::GThread, G3D::AtomicInt32, G3D::Spinlock

Constructor & Destructor Documentation

G3D::GMutex::GMutex ( const GMutex mlock)
private
G3D::GMutex::GMutex ( )
215  {
216 #ifdef G3D_WINDOWS
217  ::InitializeCriticalSection(&m_handle);
218 #else
219  int ret = pthread_mutexattr_init(&m_attr);
220  debugAssert(ret == 0);
221  ret = pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE);
222  debugAssert(ret == 0);
223  ret = pthread_mutex_init(&m_handle, &m_attr);
224  debugAssert(ret == 0);
225 #endif
226 }
#define debugAssert(exp)
Definition: debugAssert.h:160
pthread_mutexattr_t m_attr
Definition: GMutex.h:82
pthread_mutex_t m_handle
Definition: GMutex.h:81
G3D::GMutex::~GMutex ( )
228  {
229  //TODO: Debug check for locked
230 #ifdef G3D_WINDOWS
231  ::DeleteCriticalSection(&m_handle);
232 #else
233  int ret = pthread_mutex_destroy(&m_handle);
234  debugAssert(ret == 0);
235  ret = pthread_mutexattr_destroy(&m_attr);
236  debugAssert(ret == 0);
237 #endif
238 }
#define debugAssert(exp)
Definition: debugAssert.h:160
pthread_mutexattr_t m_attr
Definition: GMutex.h:82
pthread_mutex_t m_handle
Definition: GMutex.h:81

Member Function Documentation

void G3D::GMutex::lock ( )

Locks the mutex or blocks until available.

248  {
249 #ifdef G3D_WINDOWS
250  ::EnterCriticalSection(&m_handle);
251 #else
252  pthread_mutex_lock(&m_handle);
253 #endif
254 }
pthread_mutex_t m_handle
Definition: GMutex.h:81

+ Here is the caller graph for this function:

GMutex& G3D::GMutex::operator= ( const GMutex )
private
bool G3D::GMutex::operator== ( const GMutex )
private
bool G3D::GMutex::tryLock ( )

Locks the mutex if it not already locked. Returns true if lock successful, false otherwise.

240  {
241 #ifdef G3D_WINDOWS
242  return (::TryEnterCriticalSection(&m_handle) != 0);
243 #else
244  return (pthread_mutex_trylock(&m_handle) == 0);
245 #endif
246 }
pthread_mutex_t m_handle
Definition: GMutex.h:81
void G3D::GMutex::unlock ( )

Unlocks the mutex.

256  {
257 #ifdef G3D_WINDOWS
258  ::LeaveCriticalSection(&m_handle);
259 #else
260  pthread_mutex_unlock(&m_handle);
261 #endif
262 }
pthread_mutex_t m_handle
Definition: GMutex.h:81

+ Here is the caller graph for this function:

Member Data Documentation

pthread_mutexattr_t G3D::GMutex::m_attr
private
pthread_mutex_t G3D::GMutex::m_handle
private

The documentation for this class was generated from the following files: