Conscience Core
Public Member Functions | Static Public Member Functions | List of all members
conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType > Class Template Reference

Implementation of a fast shared_recursive_mutex Thanks to https://github.com/KonanM/shared_recursive_mutex. More...

#include <shared_recursive_mutex.h>

Public Member Functions

 shared_recursive_mutex_t (const shared_recursive_mutex_t &)=delete
 Copying the mutex is not allowed. More...
 
shared_recursive_mutex_toperator= (const shared_recursive_mutex_t &)=delete
 
void lock ()
 Locks the mutex for exclusive write access for this thread. Blocks execution as long as write access is not available: More...
 
void lock_shared ()
 Locks the mutex for sharable read access. Blocks execution as long as read access is not available: More...
 
void unlock ()
 Unlocks the mutex for this thread if its level of write ownership is 1 and has no read ownership. If the thread has write ownership of 1 and read ownership, the mutex will change from write to read access. Otherwise reduces the level of ownership by 1. More...
 
void unlock_shared ()
 Unlocks the mutex for this thread if its level of ownership is 1. Otherwise reduces the level of ownership by 1. More...
 
bool try_lock ()
 Tries to get write ownership if possible. If the thread has read (but no write) ownership this function returns false, because to upgrade a read lock to a write lock we have to give up read ownership, so if we can't aquire write ownership we have to reaquire the read ownership again, which might be a blocking operation. Use try_lock_upgrade is this is the wanted behavior. More...
 
bool try_lock_shared ()
 Tries to get read ownership if possible. More...
 
bool is_locked () const
 Returns if this thread has write ownership. More...
 
bool is_locked_shared () const
 Returns true if this thread has only read ownership. More...
 

Static Public Member Functions

static shared_recursive_mutex_tinstance ()
 The shared_recursive_mutex_t is relying on thread local storage, so there can only be 1 valid instance of it. More...
 

Detailed Description

template<typename PhantomType>
class conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >

Implementation of a fast shared_recursive_mutex Thanks to https://github.com/KonanM/shared_recursive_mutex.

Constructor & Destructor Documentation

◆ shared_recursive_mutex_t()

template<typename PhantomType >
conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::shared_recursive_mutex_t ( const shared_recursive_mutex_t< PhantomType > &  )
delete

Copying the mutex is not allowed.

Member Function Documentation

◆ instance()

template<typename PhantomType >
static shared_recursive_mutex_t& conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::instance ( )
inlinestatic

The shared_recursive_mutex_t is relying on thread local storage, so there can only be 1 valid instance of it.

◆ is_locked()

template<typename PhantomType >
bool conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::is_locked

Returns if this thread has write ownership.

◆ is_locked_shared()

template<typename PhantomType >
bool conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::is_locked_shared

Returns true if this thread has only read ownership.

◆ lock()

template<typename PhantomType >
void conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::lock

Locks the mutex for exclusive write access for this thread. Blocks execution as long as write access is not available:

  • other thread has write access
  • other threads try to get write access
  • other threads have read access

A thread may call lock repeatedly. Ownership will only be released after the thread makes a matching number of calls to unlock.

◆ lock_shared()

template<typename PhantomType >
void conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::lock_shared

Locks the mutex for sharable read access. Blocks execution as long as read access is not available:

  • other thread has write access
  • other threads try to get write access

A thread may call lock repeatedly. If the thread already has write access the level of write access will be increased. Ownership will only be released after the thread makes a matching number of calls to unlock_shared.

◆ operator=()

template<typename PhantomType >
shared_recursive_mutex_t& conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::operator= ( const shared_recursive_mutex_t< PhantomType > &  )
delete

◆ try_lock()

template<typename PhantomType >
bool conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::try_lock

Tries to get write ownership if possible. If the thread has read (but no write) ownership this function returns false, because to upgrade a read lock to a write lock we have to give up read ownership, so if we can't aquire write ownership we have to reaquire the read ownership again, which might be a blocking operation. Use try_lock_upgrade is this is the wanted behavior.

◆ try_lock_shared()

template<typename PhantomType >
bool conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::try_lock_shared

Tries to get read ownership if possible.

◆ unlock()

template<typename PhantomType >
void conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::unlock

Unlocks the mutex for this thread if its level of write ownership is 1 and has no read ownership. If the thread has write ownership of 1 and read ownership, the mutex will change from write to read access. Otherwise reduces the level of ownership by 1.

◆ unlock_shared()

template<typename PhantomType >
void conscience_utils::mutexutils::shared_recursive_mutex_t< PhantomType >::unlock_shared

Unlocks the mutex for this thread if its level of ownership is 1. Otherwise reduces the level of ownership by 1.


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