mCRL2
Loading...
Searching...
No Matches
mcrl2::utilities::shared_mutex Class Reference

#include <shared_mutex.h>

Public Member Functions

 shared_mutex ()
 
 ~shared_mutex ()
 
 shared_mutex (const shared_mutex &other)
 The copy/move constructor/assignment should not be called while any lock_guard or shared_guard is alive.
 
 shared_mutex (shared_mutex &&other)
 
shared_mutexoperator= (const shared_mutex &other)
 
shared_mutexoperator= (shared_mutex &&other)
 
lock_guard lock ()
 
void unlock ()
 
shared_guard lock_shared ()
 
bool is_shared_locked () const
 

Private Member Functions

void unlock_impl ()
 
void lock_shared_impl ()
 
void unlock_shared ()
 
bool is_busy () const
 
void wait_for_busy () const
 Waits for the busy flag to become false.
 
void set_forbidden (bool value)
 

Private Attributes

std::atomic< bool > m_busy_flag = false
 A boolean flag indicating whether this thread is working inside the global aterm pool.
 
std::atomic< bool > m_forbidden_flag = false
 
std::size_t m_lock_depth = 0
 It can happen that un/lock_shared calls are nested, so keep track of the nesting depth and only actually perform un/locking at the root.
 
std::shared_ptr< shared_mutex_datam_shared
 

Friends

class lock_guard
 
class shared_guard
 
class shared_mutex_pool
 

Detailed Description

An implementation of a shared mutex (also called readers-write lock in the literature) based on the notion of busy and forbidden flags.

Definition at line 117 of file shared_mutex.h.

Constructor & Destructor Documentation

◆ shared_mutex() [1/3]

mcrl2::utilities::shared_mutex::shared_mutex ( )
inline

Definition at line 120 of file shared_mutex.h.

◆ ~shared_mutex()

mcrl2::utilities::shared_mutex::~shared_mutex ( )
inline

Definition at line 126 of file shared_mutex.h.

◆ shared_mutex() [2/3]

mcrl2::utilities::shared_mutex::shared_mutex ( const shared_mutex other)
inline

The copy/move constructor/assignment should not be called while any lock_guard or shared_guard is alive.

Definition at line 132 of file shared_mutex.h.

◆ shared_mutex() [3/3]

mcrl2::utilities::shared_mutex::shared_mutex ( shared_mutex &&  other)
inline

Definition at line 138 of file shared_mutex.h.

Member Function Documentation

◆ is_busy()

bool mcrl2::utilities::shared_mutex::is_busy ( ) const
inlineprivate
Returns
True iff the shared mutex has its busy flag set.

Definition at line 287 of file shared_mutex.h.

◆ is_shared_locked()

bool mcrl2::utilities::shared_mutex::is_shared_locked ( ) const
inline
Returns
True iff the shared mutex is in the shared section

Definition at line 224 of file shared_mutex.h.

◆ lock()

lock_guard mcrl2::utilities::shared_mutex::lock ( )
inline

Definition at line 173 of file shared_mutex.h.

◆ lock_shared()

shared_guard mcrl2::utilities::shared_mutex::lock_shared ( )
inline

Acquires a shared lock on this instance, returns a shared guard that keeps the lock until it is destroyed. Or alternative, unlock_shared is called explicitly.

Definition at line 217 of file shared_mutex.h.

◆ lock_shared_impl()

void mcrl2::utilities::shared_mutex::lock_shared_impl ( )
inlineprivate

Definition at line 248 of file shared_mutex.h.

◆ operator=() [1/2]

shared_mutex & mcrl2::utilities::shared_mutex::operator= ( const shared_mutex other)
inline

Definition at line 145 of file shared_mutex.h.

◆ operator=() [2/2]

shared_mutex & mcrl2::utilities::shared_mutex::operator= ( shared_mutex &&  other)
inline

Definition at line 158 of file shared_mutex.h.

◆ set_forbidden()

void mcrl2::utilities::shared_mutex::set_forbidden ( bool  value)
inlineprivate

Definition at line 300 of file shared_mutex.h.

◆ unlock()

void mcrl2::utilities::shared_mutex::unlock ( )
inline

Definition at line 209 of file shared_mutex.h.

◆ unlock_impl()

void mcrl2::utilities::shared_mutex::unlock_impl ( )
inlineprivate

Definition at line 234 of file shared_mutex.h.

◆ unlock_shared()

void mcrl2::utilities::shared_mutex::unlock_shared ( )
inlineprivate

Definition at line 273 of file shared_mutex.h.

◆ wait_for_busy()

void mcrl2::utilities::shared_mutex::wait_for_busy ( ) const
inlineprivate

Waits for the busy flag to become false.

Definition at line 294 of file shared_mutex.h.

Friends And Related Symbol Documentation

◆ lock_guard

friend class lock_guard
friend

Definition at line 230 of file shared_mutex.h.

◆ shared_guard

friend class shared_guard
friend

Definition at line 231 of file shared_mutex.h.

◆ shared_mutex_pool

friend class shared_mutex_pool
friend

Definition at line 232 of file shared_mutex.h.

Member Data Documentation

◆ m_busy_flag

std::atomic<bool> mcrl2::utilities::shared_mutex::m_busy_flag = false
private

A boolean flag indicating whether this thread is working inside the global aterm pool.

Definition at line 306 of file shared_mutex.h.

◆ m_forbidden_flag

std::atomic<bool> mcrl2::utilities::shared_mutex::m_forbidden_flag = false
private

Definition at line 307 of file shared_mutex.h.

◆ m_lock_depth

std::size_t mcrl2::utilities::shared_mutex::m_lock_depth = 0
private

It can happen that un/lock_shared calls are nested, so keep track of the nesting depth and only actually perform un/locking at the root.

Definition at line 311 of file shared_mutex.h.

◆ m_shared

std::shared_ptr<shared_mutex_data> mcrl2::utilities::shared_mutex::m_shared
private

Definition at line 313 of file shared_mutex.h.


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