Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
UseMutex Class Reference

RAII-style mutex lock guard. More...

#include <useMutex.H>

Public Member Functions

void unlock ()
 Explicitly unlock the mutex.
 
void lock ()
 Explicitly lock the mutex.
 
 UseMutex (pthread_mutex_t *m)
 Construct and lock (pointer version)
 
 UseMutex (pthread_mutex_t &m)
 Construct and lock (reference version)
 
void enter ()
 Alias for lock()
 
void leave ()
 Alias for unlock()
 
 ~UseMutex ()
 Destructor - unlocks if allowed.
 
void disallow_unlock ()
 Prevent automatic unlock on destruction.
 
void allow_unlock ()
 Allow automatic unlock on destruction (default)
 

Private Attributes

pthread_mutex_tmutex
 
bool unlock_when_destroy
 

Detailed Description

RAII-style mutex lock guard.

Automatically acquires a lock on construction and releases it on destruction, unless explicitly disabled.

Thread Safety

This class wraps POSIX mutexes, providing the same thread safety guarantees as the underlying pthread_mutex_t. *

Definition at line 141 of file useMutex.H.

Constructor & Destructor Documentation

◆ UseMutex() [1/2]

UseMutex::UseMutex ( pthread_mutex_t m)
inline

Construct and lock (pointer version)

Parameters
mPointer to initialized mutex *

Definition at line 182 of file useMutex.H.

References lock().

◆ UseMutex() [2/2]

UseMutex::UseMutex ( pthread_mutex_t m)
inline

Construct and lock (reference version)

Parameters
mReference to initialized mutex *

Definition at line 193 of file useMutex.H.

References lock().

◆ ~UseMutex()

UseMutex::~UseMutex ( )
inline

Destructor - unlocks if allowed.

Definition at line 205 of file useMutex.H.

References unlock(), and unlock_when_destroy.

Member Function Documentation

◆ allow_unlock()

void UseMutex::allow_unlock ( )
inline

Allow automatic unlock on destruction (default)

Definition at line 215 of file useMutex.H.

References unlock_when_destroy.

◆ disallow_unlock()

void UseMutex::disallow_unlock ( )
inline

Prevent automatic unlock on destruction.

Definition at line 212 of file useMutex.H.

References unlock_when_destroy.

◆ enter()

void UseMutex::enter ( )
inline

Alias for lock()

Definition at line 199 of file useMutex.H.

References lock().

◆ leave()

void UseMutex::leave ( )
inline

Alias for unlock()

Definition at line 202 of file useMutex.H.

References unlock().

◆ lock()

void UseMutex::lock ( )
inline

Explicitly lock the mutex.

Exceptions
std::domain_errorif mutex pointer is null *

Definition at line 168 of file useMutex.H.

References ah_domain_error_if, Aleph::maps(), and mutex.

Referenced by UseMutex(), UseMutex(), and enter().

◆ unlock()

void UseMutex::unlock ( )
inline

Explicitly unlock the mutex.

Exceptions
std::domain_errorif mutex pointer is null *

Definition at line 154 of file useMutex.H.

References ah_domain_error_if, Aleph::maps(), and mutex.

Referenced by ~UseMutex(), and leave().

Member Data Documentation

◆ mutex

pthread_mutex_t* UseMutex::mutex
private

Definition at line 143 of file useMutex.H.

Referenced by lock(), and unlock().

◆ unlock_when_destroy

bool UseMutex::unlock_when_destroy
private

Definition at line 144 of file useMutex.H.

Referenced by ~UseMutex(), allow_unlock(), and disallow_unlock().


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