Ocean
Loading...
Searching...
No Matches
Ocean::DualScopedLockT< TScopedLock, TLock > Class Template Reference

This class implements a scoped lock object that locks two lock objects in a deterministic order based on their memory addresses. More...

#include <Lock.h>

Public Member Functions

 DualScopedLockT (TLock &lockA, TLock &lockB)
 Creates a new dual scoped lock object based on two given lock objects.
 
 ~DualScopedLockT ()=default
 Destructs the dual scoped lock and unlocks both internal lock objects in reverse order.
 

Protected Member Functions

 DualScopedLockT (const DualScopedLockT< TScopedLock, TLock > &object)=delete
 Disabled accessible copy operator.
 
DualScopedLockToperator= (const DualScopedLockT< TScopedLock, TLock > &object)=delete
 Disabled accessible assigns operator.
 

Protected Attributes

TScopedLock scopedLockFirst_
 Scopedlock object holding a lock on the lock with the lowest memory address.
 
TScopedLock scopedLockSecond_
 Scoped lock object holding a lock on the lock with the highest memory address.
 

Detailed Description

template<typename TScopedLock, typename TLock = Lock>
class Ocean::DualScopedLockT< TScopedLock, TLock >

This class implements a scoped lock object that locks two lock objects in a deterministic order based on their memory addresses.

This prevents potential deadlocks when two threads attempt to lock the same pair of locks in different orders.

Template Parameters
TScopedLockThe type of scoped lock object, e.g., ScopedLock
TLockThe underlying lock type
See also
Lock, ScopedLock, TemplatedScopedLock.

Constructor & Destructor Documentation

◆ DualScopedLockT() [1/2]

template<typename TScopedLock , typename TLock >
Ocean::DualScopedLockT< TScopedLock, TLock >::DualScopedLockT ( TLock &  lockA,
TLock &  lockB 
)
inlineexplicit

Creates a new dual scoped lock object based on two given lock objects.

The locks will be acquired in a deterministic order based on their memory addresses to prevent deadlock.

Parameters
lockAThe first lock object
lockBThe second lock object, must not be the same as the first lock object

◆ ~DualScopedLockT()

template<typename TScopedLock , typename TLock = Lock>
Ocean::DualScopedLockT< TScopedLock, TLock >::~DualScopedLockT ( )
default

Destructs the dual scoped lock and unlocks both internal lock objects in reverse order.

◆ DualScopedLockT() [2/2]

template<typename TScopedLock , typename TLock = Lock>
Ocean::DualScopedLockT< TScopedLock, TLock >::DualScopedLockT ( const DualScopedLockT< TScopedLock, TLock > &  object)
protecteddelete

Disabled accessible copy operator.

Parameters
objectThe object to copy

Member Function Documentation

◆ operator=()

template<typename TScopedLock , typename TLock = Lock>
DualScopedLockT & Ocean::DualScopedLockT< TScopedLock, TLock >::operator= ( const DualScopedLockT< TScopedLock, TLock > &  object)
protecteddelete

Disabled accessible assigns operator.

Parameters
objectThe right object
Returns
Reference to this object

Field Documentation

◆ scopedLockFirst_

template<typename TScopedLock , typename TLock = Lock>
TScopedLock Ocean::DualScopedLockT< TScopedLock, TLock >::scopedLockFirst_
protected

Scopedlock object holding a lock on the lock with the lowest memory address.

◆ scopedLockSecond_

template<typename TScopedLock , typename TLock = Lock>
TScopedLock Ocean::DualScopedLockT< TScopedLock, TLock >::scopedLockSecond_
protected

Scoped lock object holding a lock on the lock with the highest memory address.


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