Public Types | Public Member Functions

atscppapi::Mutex Class Reference

A mutex is mutual exclusion: a blocking lock. More...

#include <Mutex.h>

Inherits atscppapi::noncopyable.

Collaboration diagram for atscppapi::Mutex:
Collaboration graph
[legend]

Public Types

enum  Type { TYPE_NORMAL = 0, TYPE_RECURSIVE, TYPE_ERROR_CHECK }
 

The available types of Mutexes.

More...

Public Member Functions

 Mutex (Type type=TYPE_NORMAL)
 Create a mutex.
 ~Mutex ()
bool tryLock ()
 Try to take the lock, this call will NOT block if the mutex cannot be taken.
void lock ()
 Block until the lock is taken, when this call returns the thread will be holding the lock.
void unlock ()
 Unlock the lock, this call is nonblocking.

Detailed Description

A mutex is mutual exclusion: a blocking lock.

The Mutex class uses pthreads for its implmentation.

See also:
ScopedMutexLock
ScopedMutexTryLock
ScopedSharedMutexLock
ScopedSharedMutexTryLock

Definition at line 44 of file Mutex.h.


Member Enumeration Documentation

The available types of Mutexes.

Enumerator:
TYPE_NORMAL 

This type of Mutex will deadlock if locked by a thread already holding the lock.

TYPE_RECURSIVE 

This type of Mutex will allow a thread holding the lock to lock it again; however, it must be unlocked the same number of times.

TYPE_ERROR_CHECK 

This type of Mutex will return errno = EDEADLCK if a thread would deadlock by taking the lock after it already holds it.

Definition at line 50 of file Mutex.h.


Constructor & Destructor Documentation

atscppapi::Mutex::Mutex ( Type  type = TYPE_NORMAL  )  [inline]

Create a mutex.

Parameters:
type The Type of Mutex to create, the default is TYPE_NORMAL.
See also:
Type

Definition at line 62 of file Mutex.h.

References TYPE_ERROR_CHECK, TYPE_NORMAL, and TYPE_RECURSIVE.

atscppapi::Mutex::~Mutex (  )  [inline]

Definition at line 82 of file Mutex.h.


Member Function Documentation

void atscppapi::Mutex::lock (  )  [inline]

Block until the lock is taken, when this call returns the thread will be holding the lock.

Definition at line 97 of file Mutex.h.

Referenced by atscppapi::ScopedMutexLock::ScopedMutexLock().

bool atscppapi::Mutex::tryLock (  )  [inline]

Try to take the lock, this call will NOT block if the mutex cannot be taken.

Returns:
Returns true if the lock was taken, false if it was not. This call obviously will not block.

Definition at line 90 of file Mutex.h.

Referenced by atscppapi::ScopedMutexTryLock::ScopedMutexTryLock().

void atscppapi::Mutex::unlock (  )  [inline]

Unlock the lock, this call is nonblocking.

Definition at line 104 of file Mutex.h.

Referenced by atscppapi::ScopedMutexLock::~ScopedMutexLock(), and atscppapi::ScopedMutexTryLock::~ScopedMutexTryLock().


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