perfc 0.11.0
Loading...
Searching...
No Matches
perfc::Locked< T, Mutex > Class Template Reference

Simple type that provide synchronized access by holding a lock to T container. More...

#include <register.hpp>

Detailed Description

template<class T, class Mutex>
class perfc::Locked< T, Mutex >

Simple type that provide synchronized access by holding a lock to T container.

Accessing the locked object is peformed using pointer semantics.

Definition at line 57 of file register.hpp.

Public Types

using PointerType = std::add_pointer_t<T>
 
using ReferenceType = std::add_lvalue_reference_t<T>
 

Public Member Functions

 Locked (ReferenceType t, Mutex &mutex)
 Construct by providing reference to object requiring synchronized access and the mutex protecting it.
 
 Locked (Locked &&other) noexcept
 Move constructs by taking owneship of internal state of other.
 
Lockedoperator= (Locked &&other) noexcept
 Move constructs by taking owneship of internal state of other.
 
PointerType Get () const noexcept
 
ReferenceType operator* () const noexcept
 
PointerType operator-> () const noexcept
 
 operator bool () const noexcept
 
void Unlock () noexcept
 Unlocks lock.
 

Member Typedef Documentation

◆ PointerType

template<class T, class Mutex>
using perfc::Locked< T, Mutex >::PointerType = std::add_pointer_t<T>

Definition at line 59 of file register.hpp.

◆ ReferenceType

template<class T, class Mutex>
using perfc::Locked< T, Mutex >::ReferenceType = std::add_lvalue_reference_t<T>

Definition at line 60 of file register.hpp.

Constructor & Destructor Documentation

◆ Locked() [1/2]

template<class T, class Mutex>
perfc::Locked< T, Mutex >::Locked ( ReferenceType t,
Mutex & mutex )
inline

Construct by providing reference to object requiring synchronized access and the mutex protecting it.

Parameters
tObject to obtain exclusive access to.
mutexMutex protecting t.
Exceptions
Exceptionoriginating from Mutex::lock() (typically std::system_error)

Definition at line 70 of file register.hpp.

◆ Locked() [2/2]

template<class T, class Mutex>
perfc::Locked< T, Mutex >::Locked ( Locked< T, Mutex > && other)
inlinenoexcept

Move constructs by taking owneship of internal state of other.

Parameters
otherObject to move from.

Definition at line 77 of file register.hpp.

Member Function Documentation

◆ Get()

template<class T, class Mutex>
PointerType perfc::Locked< T, Mutex >::Get ( ) const
inlinenoexcept
Returns
Reference to underlying object.

Definition at line 98 of file register.hpp.

◆ operator bool()

template<class T, class Mutex>
perfc::Locked< T, Mutex >::operator bool ( ) const
inlinenoexcept
Returns
true if to underlying object is valid, false otherwise.

Definition at line 117 of file register.hpp.

◆ operator*()

template<class T, class Mutex>
ReferenceType perfc::Locked< T, Mutex >::operator* ( ) const
inlinenoexcept
Returns
Reference to underlying object.

Definition at line 104 of file register.hpp.

◆ operator->()

template<class T, class Mutex>
PointerType perfc::Locked< T, Mutex >::operator-> ( ) const
inlinenoexcept
Returns
Pointer to underlying object.

Definition at line 110 of file register.hpp.

◆ operator=()

template<class T, class Mutex>
Locked & perfc::Locked< T, Mutex >::operator= ( Locked< T, Mutex > && other)
inlinenoexcept

Move constructs by taking owneship of internal state of other.

Parameters
otherObject to move from.

Definition at line 87 of file register.hpp.

◆ Unlock()

template<class T, class Mutex>
void perfc::Locked< T, Mutex >::Unlock ( )
inlinenoexcept

Unlocks lock.

Note
There is no way to re-acquire lock after this.
Postcondition
Get() == nullptr

Definition at line 128 of file register.hpp.


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