libpsynth 0.2.1
Public Types | Public Member Functions | Friends
psynth::mutex Class Reference

A mutex is a MUTual EXclusion device, and is useful for protecting shared data structures from concurrent modifications, and implementing critical sections and monitors. More...

#include <mutex.hpp>

List of all members.

Public Types

enum  type { DEFAULT = PTHREAD_MUTEX_DEFAULT, FAST = PTHREAD_MUTEX_NORMAL, RECURSIVE = PTHREAD_MUTEX_RECURSIVE, ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK }
 Mutex type. More...

Public Member Functions

 mutex (int type=DEFAULT)
 Constuctor.
 ~mutex ()
 Destructor.
void reset (int type=DEFAULT)
 Rebuilds the mutex.
bool lock () const
 Locks the mutex.
bool try_lock () const
 Tries to lock the mutex.
void unlock () const
 Unlocks the mutex.

Friends

class condition

Detailed Description

A mutex is a MUTual EXclusion device, and is useful for protecting shared data structures from concurrent modifications, and implementing critical sections and monitors.

A mutex has two possible states: unlocked (not owned by any thread), and locked (owned by one thread). A mutex can never be owned by two different threads simultaneously. A thread attempting to lock a mutex that is already locked by another thread is suspended until the owning thread unlocks the mutex first.


Member Enumeration Documentation

Mutex type.

Enumerator:
DEFAULT 

Default mutex.

FAST 

Fast implementation but does not allow recursive locking.

RECURSIVE 

Mutex that allows recursive locks.

ERRORCHECK 

Error checking mutex.


Constructor & Destructor Documentation

psynth::mutex::mutex ( int  type = DEFAULT) [inline]

Constuctor.

Parameters:
Mutextype. Defaults to DEFAULT.
psynth::mutex::~mutex ( ) [inline]

Destructor.


Member Function Documentation

bool psynth::mutex::lock ( ) const [inline]

Locks the mutex.

If a second thread calls lock it will block until the owner of the mutex -the first thread that called lock- calls unlock.

void psynth::mutex::reset ( int  type = DEFAULT) [inline]

Rebuilds the mutex.

Parameters:
typeNew mutex type.
bool psynth::mutex::try_lock ( ) const [inline]

Tries to lock the mutex.

Returns:
true if we now own the mutex or false if the mutex is already locked.
void psynth::mutex::unlock ( ) const [inline]

Unlocks the mutex.


Friends And Related Function Documentation

friend class condition [friend]

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