Cbeam
Loading...
Searching...
No Matches
cbeam::concurrency::named_recursive_mutex Class Reference

Provides a cross-platform interface for recursive named mutexes, enabling interprocess synchronization. More...

#include <named_recursive_mutex.hpp>

Public Member Functions

 named_recursive_mutex (const std::string &name)
 Constructs a named_recursive_mutex with a specified name.
 
virtual ~named_recursive_mutex () noexcept
 Destructor for named_recursive_mutex.
 
void lock () const
 Acquires the mutex lock.
 
void unlock () const
 Releases the mutex lock.
 
 named_recursive_mutex (const named_recursive_mutex &)=delete
 
named_recursive_mutexoperator= (const named_recursive_mutex &)=delete
 
 named_recursive_mutex (named_recursive_mutex &&)=delete
 
named_recursive_mutexoperator= (named_recursive_mutex &&)=delete
 

Detailed Description

Provides a cross-platform interface for recursive named mutexes, enabling interprocess synchronization.

On Linux and Mac OS X, this class mimics the functionality of boost::interprocess::named_recursive_mutex. On Windows, it utilizes the native Windows API for named mutexes, which differs from Linux and Mac OS X in:

  • Non-persistent mutexes: they get destroyed when the last referencing process terminates.
  • Limited to the same user session. This implementation opts for the native Windows approach over the Boost library to leverage platform-specific optimizations and circumvent file system permission issues commonly encountered with C:\ProgramData\boost_interprocess.

Constructor & Destructor Documentation

◆ named_recursive_mutex() [1/3]

cbeam::concurrency::named_recursive_mutex::named_recursive_mutex ( const std::string & name)
inline

Constructs a named_recursive_mutex with a specified name.

Initializes the mutex based on the operating system. On Windows, it creates a native mutex using CreateMutexA. On Unix-based systems, it sets up a shared memory and initializes a pthread mutex.

Exceptions
cbeam::error::system_errorThrown if mutex creation or initialization fails.
Parameters
nameThe unique name of the mutex for interprocess identification.

◆ ~named_recursive_mutex()

virtual cbeam::concurrency::named_recursive_mutex::~named_recursive_mutex ( )
inlinevirtualnoexcept

Destructor for named_recursive_mutex.

Cleans up resources allocated for the mutex. On Windows, it closes the handle to the mutex. On Unix-based systems, it destroys the pthread mutex and unmaps the shared memory.

◆ named_recursive_mutex() [2/3]

cbeam::concurrency::named_recursive_mutex::named_recursive_mutex ( const named_recursive_mutex & )
delete

◆ named_recursive_mutex() [3/3]

cbeam::concurrency::named_recursive_mutex::named_recursive_mutex ( named_recursive_mutex && )
delete

Member Function Documentation

◆ lock()

void cbeam::concurrency::named_recursive_mutex::lock ( ) const
inline

Acquires the mutex lock.

On Windows, it uses WaitForSingleObject to wait for the mutex. On Unix-based systems, it locks the pthread mutex.

Exceptions
cbeam::error::system_errorThrown if locking the mutex fails.

◆ operator=() [1/2]

named_recursive_mutex & cbeam::concurrency::named_recursive_mutex::operator= ( const named_recursive_mutex & )
delete

◆ operator=() [2/2]

named_recursive_mutex & cbeam::concurrency::named_recursive_mutex::operator= ( named_recursive_mutex && )
delete

◆ unlock()

void cbeam::concurrency::named_recursive_mutex::unlock ( ) const
inline

Releases the mutex lock.

On Windows, it releases the mutex using ReleaseMutex. On Unix-based systems, it unlocks the pthread mutex.

Exceptions
cbeam::error::system_errorThrown if unlocking the mutex fails.

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