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

RAII guard for exclusive access to the synchronized value. More...

#include <concurrency_utils.H>

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

Public Member Functions

 LockedPtr (Mutex &mutex, T &value)
 Construct a guard and acquire the lock.
 
Tget () noexcept
 Access the protected value.
 
Toperator-> () noexcept
 Access members of the protected value.
 
Toperator* () noexcept
 Access the protected value.
 

Private Attributes

std::unique_lock< Mutexlock_
 
Tptr_
 

Detailed Description

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

RAII guard for exclusive 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.

Definition at line 712 of file concurrency_utils.H.

Constructor & Destructor Documentation

◆ LockedPtr()

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

Member Function Documentation

◆ get()

template<typename T , typename Mutex = std::mutex>
T & Aleph::Synchronized< T, Mutex >::LockedPtr::get ( )
inlinenoexcept

Access the protected value.

Returns
A mutable reference to the protected object.
Exceptions
Nothing.

Definition at line 730 of file concurrency_utils.H.

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

◆ operator*()

template<typename T , typename Mutex = std::mutex>
T & Aleph::Synchronized< T, Mutex >::LockedPtr::operator* ( )
inlinenoexcept

Access the protected value.

Returns
A mutable reference to the protected object.
Exceptions
Nothing.

Definition at line 740 of file concurrency_utils.H.

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

◆ operator->()

template<typename T , typename Mutex = std::mutex>
T * Aleph::Synchronized< T, Mutex >::LockedPtr::operator-> ( )
inlinenoexcept

Access members of the protected value.

Returns
A mutable pointer to the protected object.
Exceptions
Nothing.

Definition at line 735 of file concurrency_utils.H.

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

Member Data Documentation

◆ lock_

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

Definition at line 714 of file concurrency_utils.H.

◆ ptr_


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