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

RAII guard for exclusive (write) access. More...

#include <concurrency_utils.H>

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

Public Member Functions

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

Private Attributes

std::unique_lock< SharedMutex > lock_
 
T * ptr_
 

Detailed Description

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

RAII guard for exclusive (write) access.

Note
The guard holds an exclusive 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 1083 of file concurrency_utils.H.

Constructor & Destructor Documentation

◆ WriteLockedPtr() [1/2]

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

Construct a guard and acquire an exclusive lock.

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

Definition at line 1094 of file concurrency_utils.H.

◆ WriteLockedPtr() [2/2]

template<typename T , typename SharedMutex = std::shared_mutex>
Aleph::RwSynchronized< T, SharedMutex >::WriteLockedPtr::WriteLockedPtr ( WriteLockedPtr &&  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 1105 of file concurrency_utils.H.

Member Function Documentation

◆ get()

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

Access the protected value.

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

Definition at line 1126 of file concurrency_utils.H.

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

◆ operator*()

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

Access the protected value.

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

Definition at line 1142 of file concurrency_utils.H.

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

◆ operator->()

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

Access members of the protected value.

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

Definition at line 1136 of file concurrency_utils.H.

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

◆ operator=()

template<typename T , typename SharedMutex = std::shared_mutex>
WriteLockedPtr & Aleph::RwSynchronized< T, SharedMutex >::WriteLockedPtr::operator= ( WriteLockedPtr &&  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 1113 of file concurrency_utils.H.

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

Member Data Documentation

◆ lock_

template<typename T , typename SharedMutex = std::shared_mutex>
std::unique_lock<SharedMutex> Aleph::RwSynchronized< T, SharedMutex >::WriteLockedPtr::lock_
private

◆ ptr_


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