Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

FastMutex Class Reference

This class implements a standard fast = non-recursive mutex (mutual exclusion device). More...

#include <mutex.h>

Collaboration diagram for FastMutex:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FastMutex ()
 Create a fast mutex.

 ~FastMutex ()
void lock ()
 Lock the mutex.

bool test ()
 Try to lock the mutex: Non-blocking variant of lock().

void unlock ()
 Unlock the mutex.


Private Attributes

GStaticMutex m

Friends

class WaitCondition

Detailed Description

This class implements a standard fast = non-recursive mutex (mutual exclusion device).

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Note:
You should always use the RecursiveMutex unless you are sure that a FastMutex can be used.

You CAN rely on RecursiveMutex being recursive but you should not rely on FastMutex being NOT recursive.

If you do not know what a mutex is and what it is good for, you should read some docu about parallel programming / threads first.
And make sure to declare the FastMutex statically or before the threads are created, otherwise they will not work at all...

Definition at line 54 of file mutex.h.


Constructor & Destructor Documentation

FastMutex::FastMutex  ) 
 

Create a fast mutex.

Definition at line 20 of file mutex.cc.

References m.

FastMutex::~FastMutex  )  [inline]
 

Destroy a mutex. Make sure that the mutex is unlocked before destroying it.

Definition at line 70 of file mutex.h.

References m, and USE_PRIVATE__PTHREADS.


Member Function Documentation

void FastMutex::lock  )  [inline]
 

Lock the mutex.

If the mutex is currently unlocked, it becomes locked and owned by the calling thread, and the function returns immediately. If the mutex is already locked by another thread, this function suspends the calling thread until the mutex is unlocked. MAKE SURE that the mutex is NOT currently locked by the calling thread; otherwise deadlock occurs. Or, use a recursive mutex such as RecursiveMutex.

Definition at line 89 of file mutex.h.

References m, and USE_PRIVATE__PTHREADS.

bool FastMutex::test  )  [inline]
 

Try to lock the mutex: Non-blocking variant of lock().

Returns:
Returns 0 if the mutex is busy, otherwise lock mutex and return 1.

Definition at line 102 of file mutex.h.

References m, and USE_PRIVATE__PTHREADS.

void FastMutex::unlock  )  [inline]
 

Unlock the mutex.

The mutex is assumed to be locked and owned by the calling thread on entrance to this function. The thread will always be unlocked by a call to this function.

Definition at line 115 of file mutex.h.

References m, and USE_PRIVATE__PTHREADS.


Friends And Related Function Documentation

friend class WaitCondition [friend]
 

Definition at line 56 of file mutex.h.


Member Data Documentation

GStaticMutex FastMutex::m [private]
 

Definition at line 61 of file mutex.h.

Referenced by FastMutex(), lock(), test(), unlock(), and ~FastMutex().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:25 2005 for Ray by doxygen 1.3.5