Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr Class Reference

RAII guard for shared (read-only) access. More...

#include <concurrency_utils.H>

Collaboration diagram for Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr:
[legend]

Public Member Functions

 ReadLockedPtr (SharedMutex &mutex, const T &value)
 Construct a guard and acquire a shared lock.
 
 ReadLockedPtr (ReadLockedPtr &&other) noexcept
 Take the lock and the access of another guard, which is left with neither.
 
ReadLockedPtr & operator= (ReadLockedPtr &&other) noexcept
 Release the lock of this guard and take the lock and the access of another, which is left with neither.
 
const T & get () const noexcept
 Access the protected value.
 
const T * operator-> () const noexcept
 Access members of the protected value.
 
const T & operator* () const noexcept
 Access the protected value.
 

Private Attributes

std::shared_lock< SharedMutex > lock_
 
const T * ptr_
 

Detailed Description

template<typename T, typename SharedMutex = std::shared_mutex>
class Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr

RAII guard for shared (read-only) access.

Note
The guard holds a shared lock until destruction.
A moved-from guard holds no lock and gives no access: its operator->() returns nullptr, and get() and operator*() must not be called on it (asserted in Debug builds).

Definition at line 1011 of file concurrency_utils.H.

Constructor & Destructor Documentation

◆ ReadLockedPtr() [1/2]

template<typename T , typename SharedMutex = std::shared_mutex>
Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ReadLockedPtr ( SharedMutex &  mutex,
const T &  value 
)
inline

Construct a guard and acquire a shared lock.

Parameters
mutexShared mutex protecting the value.
valueProtected object to expose through the guard.
Exceptions
Anyexception thrown while locking mutex.

Definition at line 1022 of file concurrency_utils.H.

◆ ReadLockedPtr() [2/2]

template<typename T , typename SharedMutex = std::shared_mutex>
Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ReadLockedPtr ( ReadLockedPtr &&  other)
inlinenoexcept

Take the lock and the access of another guard, which is left with neither.

The implicit move took the lock but copied the pointer: the moved-from guard still gave the value, with no lock held.

Parameters
[in,out]otherguard to move from.

Definition at line 1033 of file concurrency_utils.H.

Member Function Documentation

◆ get()

template<typename T , typename SharedMutex = std::shared_mutex>
const T & Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::get ( ) const
inlinenoexcept

Access the protected value.

Returns
A const reference to the protected object.
Exceptions
Nothing.
Precondition
The guard was not moved from.

Definition at line 1054 of file concurrency_utils.H.

References Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ptr_.

◆ operator*()

template<typename T , typename SharedMutex = std::shared_mutex>
const T & Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::operator* ( ) const
inlinenoexcept

Access the protected value.

Returns
A const reference to the protected object.
Exceptions
Nothing.
Precondition
The guard was not moved from.

Definition at line 1070 of file concurrency_utils.H.

References Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ptr_.

◆ operator->()

template<typename T , typename SharedMutex = std::shared_mutex>
const T * Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::operator-> ( ) const
inlinenoexcept

Access members of the protected value.

Returns
A const pointer to the protected object, or nullptr if the guard was moved from.
Exceptions
Nothing.

Definition at line 1064 of file concurrency_utils.H.

References Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ptr_.

◆ operator=()

template<typename T , typename SharedMutex = std::shared_mutex>
ReadLockedPtr & Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::operator= ( ReadLockedPtr &&  other)
inlinenoexcept

Release the lock of this guard and take the lock and the access of another, which is left with neither.

Parameters
[in,out]otherguard to move from.
Returns
this guard.

Definition at line 1041 of file concurrency_utils.H.

References Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::lock_, and Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::ptr_.

Member Data Documentation

◆ lock_

template<typename T , typename SharedMutex = std::shared_mutex>
std::shared_lock<SharedMutex> Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr::lock_
private

◆ ptr_


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