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

Legacy 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

Legacy RAII-style mutex lock guard.

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

Deprecated:
Prefer Aleph::synchronized<T>, std::lock_guard, or std::unique_lock in new code.

Thread Safety

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

Definition at line 150 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 191 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 202 of file useMutex.H.

References lock().

◆ ~UseMutex()

UseMutex::~UseMutex ( )
inline

Destructor - unlocks if allowed.

Definition at line 214 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 224 of file useMutex.H.

References unlock_when_destroy.

◆ disallow_unlock()

void UseMutex::disallow_unlock ( )
inline

Prevent automatic unlock on destruction.

Definition at line 221 of file useMutex.H.

References unlock_when_destroy.

◆ enter()

void UseMutex::enter ( )
inline

Alias for lock()

Definition at line 208 of file useMutex.H.

References lock().

◆ leave()

void UseMutex::leave ( )
inline

Alias for unlock()

Definition at line 211 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 177 of file useMutex.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), 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 163 of file useMutex.H.

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

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

Member Data Documentation

◆ mutex

pthread_mutex_t* UseMutex::mutex
private

Definition at line 152 of file useMutex.H.

Referenced by lock(), and unlock().

◆ unlock_when_destroy

bool UseMutex::unlock_when_destroy
private

Definition at line 153 of file useMutex.H.

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


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