Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

rwil::Mutex Class Reference

A mutex class. More...

#include <Synchronization.h>

List of all members.

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...


Detailed Description

A mutex class.

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.


Constructor & Destructor Documentation

rwil::Mutex::Mutex  
 

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   }

rwil::Mutex::~Mutex  
 

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   }


Member Function Documentation

void rwil::Mutex::Release  
 

Release the mutex.

Unpredictable results occur when the mutex is not held before this call.

bool rwil::Mutex::TryWait  
 

Try to wait on a mutex.

This returns immediately.

Returns:
True if the mutex is acquired, false if not

void rwil::Mutex::Wait  
 

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.


The documentation for this class was generated from the following files:
Generated on Tue Apr 9 13:53:08 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001