DART  6.7.3
dart::common::MultiLockableReference< LockableT > Class Template Referencefinal

MultiLockableReference references multiple lockables. More...

#include <LockableReference.hpp>

Inheritance diagram for dart::common::MultiLockableReference< LockableT >:
dart::common::LockableReference

Public Types

using Lockable = LockableT
 

Public Member Functions

template<typename InputIterator >
 MultiLockableReference (std::weak_ptr< const void > lockableHolder, InputIterator first, InputIterator last)
 Constructs from multiple lockables. More...
 
void lock () override
 Locks lockable that this class references; blocks if one of the lockables are not avaliable. More...
 
bool try_lock () noexcept override
 Tries to lock the lockables that this class references; returns false if one of the lockables is not avaliable. More...
 
void unlock () noexcept override
 Unlocks the lockables. More...
 

Private Member Functions

template<typename T >
T * ptr (T &obj)
 Converts reference to pointer. More...
 
template<typename T >
T * ptr (T *obj)
 Returns pointer as it is. More...
 

Private Attributes

std::weak_ptr< const void > mLockableHolder
 Weak pointer to the lockable holder. More...
 
std::vector< Lockable * > mLockables
 lockables this class references. More...
 

Detailed Description

template<typename LockableT>
class dart::common::MultiLockableReference< LockableT >

MultiLockableReference references multiple lockables.

MultiLockableReference acquires the locks in the specified order, which means it is the user's responsibility to sort the collection to avoid deadlock.

Template Parameters
LockableTThe standard C++ Lockable concept object type.

Member Typedef Documentation

◆ Lockable

template<typename LockableT >
using dart::common::MultiLockableReference< LockableT >::Lockable = LockableT

Constructor & Destructor Documentation

◆ MultiLockableReference()

template<typename Lockable >
template<typename InputIterator >
dart::common::MultiLockableReference< Lockable >::MultiLockableReference ( std::weak_ptr< const void >  lockableHolder,
InputIterator  first,
InputIterator  last 
)

Constructs from multiple lockables.

Parameters
[in]lockableHolderWeak pointer to an object that holds the lockables. This is used to lock/unlock this lockable only when the lockable holder is not destructed.
[in]firstFirst iterator of lockable to be added to this class.
[in]lastLast iterator of lockable to be added to this class.

Member Function Documentation

◆ lock()

template<typename Lockable >
void dart::common::MultiLockableReference< Lockable >::lock ( )
overridevirtual

Locks lockable that this class references; blocks if one of the lockables are not avaliable.

Implements dart::common::LockableReference.

◆ ptr() [1/2]

template<typename Lockable >
template<typename T >
T * dart::common::MultiLockableReference< Lockable >::ptr ( T &  obj)
private

Converts reference to pointer.

◆ ptr() [2/2]

template<typename Lockable >
template<typename T >
T * dart::common::MultiLockableReference< Lockable >::ptr ( T *  obj)
private

Returns pointer as it is.

◆ try_lock()

template<typename Lockable >
bool dart::common::MultiLockableReference< Lockable >::try_lock ( )
overridevirtualnoexcept

Tries to lock the lockables that this class references; returns false if one of the lockables is not avaliable.

Implements dart::common::LockableReference.

◆ unlock()

template<typename Lockable >
void dart::common::MultiLockableReference< Lockable >::unlock ( )
overridevirtualnoexcept

Unlocks the lockables.

Implements dart::common::LockableReference.

Member Data Documentation

◆ mLockableHolder

template<typename LockableT >
std::weak_ptr<const void> dart::common::MultiLockableReference< LockableT >::mLockableHolder
private

Weak pointer to the lockable holder.

◆ mLockables

template<typename LockableT >
std::vector<Lockable*> dart::common::MultiLockableReference< LockableT >::mLockables
private

lockables this class references.