SGMutex Class Reference

A mutex is used to protect a section of code such that at any time only a single thread can execute the code. More...

#include <SGThread.hxx>

List of all members.

Public Member Functions

 SGMutex ()
 Create a new mutex.
 ~SGMutex ()
 Destroy a mutex object.
void lock ()
 Lock this mutex.
bool trylock ()
 Try to lock the mutex for the current thread.
void unlock ()
 Unlock this mutex.

Protected Attributes

pthread_mutex_t mutex
 Pthread mutex.

Friends

class SGPthreadCond

Detailed Description

A mutex is used to protect a section of code such that at any time only a single thread can execute the code.

Definition at line 162 of file SGThread.hxx.


Constructor & Destructor Documentation

SGMutex::SGMutex (  )  [inline]

Create a new mutex.

Under Linux this is a 'fast' mutex.

Definition at line 216 of file SGThread.hxx.

SGMutex::~SGMutex (  )  [inline]

Destroy a mutex object.

Note: it is the responsibility of the caller to ensure the mutex is unlocked before destruction occurs.

Definition at line 223 of file SGThread.hxx.


Member Function Documentation

void SGMutex::lock ( void   )  [inline]

Lock this mutex.

If the mutex is currently unlocked, it becomes locked and owned by the calling thread. If the mutex is already locked by another thread, the calling thread is suspended until the mutex is unlocked. If the mutex is already locked and owned by the calling thread, the calling thread is suspended until the mutex is unlocked, effectively causing the calling thread to deadlock.

See also:
SGMutex::trylock

Definition at line 230 of file SGThread.hxx.

bool SGMutex::trylock (  ) 

Try to lock the mutex for the current thread.

Behaves like lock except that it doesn't block the calling thread.

Returns:
true if mutex was successfully locked, otherwise false.
See also:
SGMutex::lock

Definition at line 49 of file SGThread.cxx.

void SGMutex::unlock (  )  [inline]

Unlock this mutex.

It is assumed that the mutex is locked and owned by the calling thread.

Definition at line 237 of file SGThread.hxx.


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

Generated on 23 Feb 2010 for SimGear by  doxygen 1.6.1