EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
ConstStrictLockPtr< T, LockType > Class Template Reference

Overview

template<typename T, typename LockType = Mutex>
class etcpal::ConstStrictLockPtr< T, LockType >

An RAII handle holding a SynchronizedValue's lock and granting read-only access to the value.

The lock is acquired when the handle is constructed and released when it is destroyed. Handles are normally obtained from SynchronizedValue rather than constructed directly. Move-only.

Note
ConstStrictLockPtr implies the lock is held, but this fails to be true if moved.
Template Parameters
TThe type of the guarded value.
LockTypeThe type of lock guarding the value.

Public Member Functions

 ConstStrictLockPtr (const SynchronizedValue< T, LockType > &sync)
 Lock the given SynchronizedValue for read-only access. More...
 
 ConstStrictLockPtr (const SynchronizedValue< T, LockType > &sync, AdoptLockTag) noexcept
 Adopt the given SynchronizedValue's lock, which the calling thread must already hold.
 
 ConstStrictLockPtr (ConstUniqueLockPtr< T, LockType > &&other)
 Take over the lock held by other, which is left empty. More...
 
 ConstStrictLockPtr (const ConstStrictLockPtr &)=delete
 
ConstStrictLockPtroperator= (const ConstStrictLockPtr &)=delete
 
ConstStrictLockPtroperator= (ConstStrictLockPtr &&)=delete
 
 ConstStrictLockPtr (ConstStrictLockPtr &&other) noexcept
 Move ownership of the held lock from another handle, which is left empty.
 
 ~ConstStrictLockPtr () noexcept
 Release the lock.
 
const T & operator* () const noexcept
 Get a reference to the guarded value. Undefined behavior if this handle has been moved from.
 
const T * operator-> () const noexcept
 Access a member of the guarded value. Undefined behavior if this handle has been moved from.
 

Protected Attributes

const SynchronizedValue< T, LockType > * sync_
 

Constructor & Destructor Documentation

◆ ConstStrictLockPtr() [1/2]

ConstStrictLockPtr ( const SynchronizedValue< T, LockType > &  sync)
inlineexplicit

Lock the given SynchronizedValue for read-only access.

Exceptions
std::runtime_errorif lock could not be acquired.

◆ ConstStrictLockPtr() [2/2]

ConstStrictLockPtr ( ConstUniqueLockPtr< T, LockType > &&  other)
inlineexplicit

Take over the lock held by other, which is left empty.

Exceptions
std::runtime_errorif other does not own the lock.

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