libcommonc++  0.7
Mutex Class Reference

A mutual-exclusion lock. More...

#include <Mutex.h++>

Inheritance diagram for Mutex:
Collaboration diagram for Mutex:

Public Member Functions

 Mutex (bool recursive=false)
 Construct a new Mutex. More...
 
 ~Mutex ()
 Destructor. More...
 
void lock ()
 Lock the mutex, blocking until the lock is acquired. More...
 
bool tryLock (timespan_ms_t timeout=0)
 Try to lock the mutex, returning if it could not be acquired within the given amount of time. More...
 
void unlock ()
 Unlock the mutex. More...
 
bool isRecursive () const
 Determine if this mutex is recursive. More...
 

Static Public Member Functions

static bool supportsTimedLocks ()
 Determine if the host system supports timed mutex locks. More...
 

Friends

class ConditionVar
 

Detailed Description

A mutual-exclusion lock.

Only one thread may have a Mutex locked at any one time.

A Mutex may be created as recursive; such a Mutex can be re-locked by a thread that already holds the lock on that Mutex. However, the thread must unlock the Mutex the same number of times that it has locked it in order for it to become available for locking by other threads.

See also ScopedLock.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ Mutex()

Mutex ( bool  recursive = false)

Construct a new Mutex.

Parameters
recursiveA flag indicating whether the mutex will be recursive. A recursive mutex can be re-entered by a thread that already holds the mutex.

◆ ~Mutex()

~Mutex ( )

Destructor.

Note that destroying a locked mutex can lead to deadlock.

Member Function Documentation

◆ isRecursive()

bool isRecursive ( ) const
inline

Determine if this mutex is recursive.

◆ lock()

void lock ( )
virtual

Lock the mutex, blocking until the lock is acquired.

Implements Lock.

◆ supportsTimedLocks()

bool supportsTimedLocks ( )
static

Determine if the host system supports timed mutex locks.

◆ tryLock()

bool tryLock ( timespan_ms_t  timeout = 0)

Try to lock the mutex, returning if it could not be acquired within the given amount of time.

On platforms that do not support timed mutex locks, the method returns immediately if the lock could not be acquired. On some platforms (notably Linux), recursive mutexes do not support timed locks; on these platforms, tryLock() behaves identically to lock() when applied to a recursive mutex.

Parameters
timeoutThe timeout, in milliseconds.
Returns
true if the lock was acquired, false otherwise.

◆ unlock()

void unlock ( )
virtual

Unlock the mutex.

Implements Lock.

Friends And Related Function Documentation

◆ ConditionVar

friend class ConditionVar
friend

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