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

RAII guard for read-only access to the synchronized value. More...

#include <concurrency_utils.H>

Collaboration diagram for Aleph::Synchronized< T, Mutex >::ConstLockedPtr:
[legend]

Public Member Functions

 ConstLockedPtr (Mutex &mutex, const T &value)
 Construct a guard and acquire the lock.
 
 ConstLockedPtr (ConstLockedPtr &&other) noexcept
 Take the lock and the access of another guard, which is left with neither.
 
ConstLockedPtr & operator= (ConstLockedPtr &&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::unique_lock< Mutex > lock_
 
const T * ptr_
 

Detailed Description

template<typename T, typename Mutex = std::mutex>
class Aleph::Synchronized< T, Mutex >::ConstLockedPtr

RAII guard for read-only access to the synchronized value.

Note
Thread-safe to use only while the guard object remains alive on the thread that acquired it. The destructor releases the lock.
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 809 of file concurrency_utils.H.

Constructor & Destructor Documentation

◆ ConstLockedPtr() [1/2]

template<typename T , typename Mutex = std::mutex>
Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ConstLockedPtr ( Mutex &  mutex,
const T &  value 
)
inline

Construct a guard and acquire the lock.

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

Definition at line 820 of file concurrency_utils.H.

◆ ConstLockedPtr() [2/2]

template<typename T , typename Mutex = std::mutex>
Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ConstLockedPtr ( ConstLockedPtr &&  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 831 of file concurrency_utils.H.

Member Function Documentation

◆ get()

template<typename T , typename Mutex = std::mutex>
const T & Aleph::Synchronized< T, Mutex >::ConstLockedPtr::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 852 of file concurrency_utils.H.

References Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ptr_.

◆ operator*()

template<typename T , typename Mutex = std::mutex>
const T & Aleph::Synchronized< T, Mutex >::ConstLockedPtr::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 868 of file concurrency_utils.H.

References Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ptr_.

◆ operator->()

template<typename T , typename Mutex = std::mutex>
const T * Aleph::Synchronized< T, Mutex >::ConstLockedPtr::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 862 of file concurrency_utils.H.

References Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ptr_.

◆ operator=()

template<typename T , typename Mutex = std::mutex>
ConstLockedPtr & Aleph::Synchronized< T, Mutex >::ConstLockedPtr::operator= ( ConstLockedPtr &&  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 839 of file concurrency_utils.H.

References Aleph::Synchronized< T, Mutex >::ConstLockedPtr::lock_, and Aleph::Synchronized< T, Mutex >::ConstLockedPtr::ptr_.

Member Data Documentation

◆ lock_

template<typename T , typename Mutex = std::mutex>
std::unique_lock<Mutex> Aleph::Synchronized< T, Mutex >::ConstLockedPtr::lock_
private

◆ ptr_


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