ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::threads::RecursiveTimedLock Class Reference

Description:

This class is a simple wrapper around C++ standard library type std::recursive_timed_mutex. Thus, it is used to implement mutual exclusive access to resources by protecting critical code sections from being executed in parallel in concurrent threads.
With release-compilations, the only difference to using std::recursive_timed_mutex directly is that "spurious wake-ups" are detected and mitigated by this implementation.

code block, then it is recommended to use a stack instantiation of class OwnerRecursive to acquire and release objects of this class. Such a use is highly simplified with macros ALIB_LOCK_RECURSIVE and ALIB_LOCK_RECURSIVE_WITH.

Nested acquisitions are supported with this type. An instance of this class is released when an equal number of invocations to AcquireRecursive and ReleaseRecursive have been performed.
This class has slightly reduced performance in comparison to non-recursive type Lock. Not only for this reason, non-nested locking is the preferred technique. But there are situations where nested locks are just unavoidable.

Debug-Features
Public member Dbg is available with debug-compilations. It offers the following features:
  • The object stores the actual owning thread and the source code position of the last acquirement.
  • Releasing non-acquired instances, as well as destructing acquired one, raise an assertion.
  • A warning threshold for the number of nested acquisitions can be defined with public member DbgLockAsserter::RecursionLimit.
  • Field WaitTimeLimit enables the raise of ALib warnings in case a certain wait time is exceeded.
Availability
This type is not available if the compiler-symbol ALIB_SINGLE_THREADED is set.
See also

Definition at line 47 of file recursivetimedlock.inl.

Inheritance diagram for alib::threads::RecursiveTimedLock:
[legend]
Collaboration diagram for alib::threads::RecursiveTimedLock:
[legend]

Public Field Index:

DbgLockAsserter Dbg
 The debug tool instance.
 

Public Method Index:

 ~RecursiveTimedLock () override
 Destructor. With debug-compilations, asserts that this lock is not acquired.
 
ALIB_DLL void AcquireRecursive (ALIB_DBG_TAKE_CI)
 
virtual ALIB_DLL bool DCSIsAcquired () const override
 
virtual ALIB_DLL bool DCSIsSharedAcquired () const override
 
ALIB_DLL void ReleaseRecursive (ALIB_DBG_TAKE_CI)
 
ALIB_DLL bool TryAcquire (ALIB_DBG_TAKE_CI)
 
bool TryAcquireTimed (const Ticks &pointInTime, const CallerInfo &ci)
 
ALIB_DLL bool TryAcquireTimed (const Ticks::Duration &waitDuration, const CallerInfo &ci)
 
bool TryAcquireTimed (const Ticks::Duration::TDuration &waitDuration, const CallerInfo &ci)
 
bool TryAcquireTimed (const Ticks::TTimePoint &pointInTime, const CallerInfo &ci)
 
- Public Method Index: inherited from alib::lang::DbgCriticalSections::AssociatedLock
virtual ~AssociatedLock ()
 Virtual Destructor.
 

Protected Field Index:

std::recursive_timed_mutex mutex
 The internal object to lock on.
 

Field Details:

◆ Dbg

DbgLockAsserter alib::threads::RecursiveTimedLock::Dbg

The debug tool instance.

Definition at line 59 of file recursivetimedlock.inl.

◆ mutex

std::recursive_timed_mutex alib::threads::RecursiveTimedLock::mutex
protected

The internal object to lock on.

Definition at line 54 of file recursivetimedlock.inl.

Constructor(s) / Destructor Details:

◆ ~RecursiveTimedLock()

alib::threads::RecursiveTimedLock::~RecursiveTimedLock ( )
inlineoverride

Destructor. With debug-compilations, asserts that this lock is not acquired.

Definition at line 64 of file recursivetimedlock.inl.

Method Details:

◆ AcquireRecursive()

void alib::threads::RecursiveTimedLock::AcquireRecursive ( ALIB_DBG_TAKE_CI )

Thread which invokes this method gets registered as the current owner of this object, until the same thread releases the ownership invoking ReleaseRecursive. In the case that this object is already owned by another thread, the invoking thread is suspended until ownership can be gained. Multiple (nested) calls to this method are counted and the object is only released when the same number of Release() calls have been made.

Debug Parameter:
Pass macro ALIB_CALLER_PRUNED with invocations.

Definition at line 306 of file locks.cpp.

Here is the call graph for this function:

◆ DCSIsAcquired()

bool alib::threads::RecursiveTimedLock::DCSIsAcquired ( ) const
overridevirtual
Returns
true if the lock is acquired (in non-shared mode), false otherwise.

Implements alib::lang::DbgCriticalSections::AssociatedLock.

Definition at line 765 of file locks.cpp.

◆ DCSIsSharedAcquired()

bool alib::threads::RecursiveTimedLock::DCSIsSharedAcquired ( ) const
overridevirtual
Returns
true if the lock is shared-acquired (by at least any thread). Otherwise, returns false.

Implements alib::lang::DbgCriticalSections::AssociatedLock.

Definition at line 766 of file locks.cpp.

◆ ReleaseRecursive()

void alib::threads::RecursiveTimedLock::ReleaseRecursive ( ALIB_DBG_TAKE_CI )

Releases ownership of this object. If AcquireRecursive was called multiple times before, the same number of calls to this method has to be performed to release ownership.

Debug Parameter:
Pass macro ALIB_CALLER_PRUNED with invocations.

Definition at line 408 of file locks.cpp.

◆ TryAcquire()

bool alib::threads::RecursiveTimedLock::TryAcquire ( ALIB_DBG_TAKE_CI )
nodiscard

Tries to acquire this lock. Successful calls to this method are counted, as if AcquireRecursive was called and an according invocation of ReleaseRecursive has to be performed.

Debug Parameter:
Pass macro ALIB_CALLER_PRUNED with invocations.
Returns
true if the lock was not acquired by a different thread and thus, this call was successful. false otherwise.

Definition at line 352 of file locks.cpp.

◆ TryAcquireTimed() [1/4]

bool alib::threads::RecursiveTimedLock::TryAcquireTimed ( const Ticks & pointInTime,
const CallerInfo & ci )
inlinenodiscard

Same as overloaded sibling, but expects a point in time rather than an Ticks::Duration.

Parameters
pointInTimeThe point in time, when this method stops waiting.
ciCaller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations.
Returns
true if the lock was acquired, false if the pointInTime was reached without successful acquisition.

Definition at line 146 of file recursivetimedlock.inl.

Here is the call graph for this function:

◆ TryAcquireTimed() [2/4]

bool alib::threads::RecursiveTimedLock::TryAcquireTimed ( const Ticks::Duration & waitDuration,
const CallerInfo & ci )
nodiscard

A thread which invokes this method gets registered as the current owner of this object, until the same thread releases the ownership invoking ReleaseRecursive. In the case that this object is already owned by another thread, the invoking thread is suspended until ownership can be gained.
Successful calls to this method are counted, as if AcquireRecursive was called and an according invocation of ReleaseRecursive has to be performed.

Parameters
waitDurationThe maximum time-span to wait.
ciCaller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations.
Returns
true if the lock was acquired, false if the waitDuration expired without successful acquisition

Definition at line 376 of file locks.cpp.

Here is the call graph for this function:

◆ TryAcquireTimed() [3/4]

bool alib::threads::RecursiveTimedLock::TryAcquireTimed ( const Ticks::Duration::TDuration & waitDuration,
const CallerInfo & ci )
inlinenodiscard

Same as overloaded sibling, but expects a C++ standard library duration type rather than an Ticks::Duration.

Parameters
waitDurationThe point in time, when this method stops waiting.
ciCaller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations.
Returns
true if the lock was acquired, false if the pointInTime was reached without successful acquisition.

Definition at line 136 of file recursivetimedlock.inl.

Here is the call graph for this function:

◆ TryAcquireTimed() [4/4]

bool alib::threads::RecursiveTimedLock::TryAcquireTimed ( const Ticks::TTimePoint & pointInTime,
const CallerInfo & ci )
inlinenodiscard

Same as overloaded sibling, but expects a C++ standard library point in time type rather than an Ticks::Duration.

Parameters
pointInTimeThe point in time, when this method stops waiting.
ciCaller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations.
Returns
true if the lock was acquired, false if the pointInTime was reached without successful acquisition.

Definition at line 158 of file recursivetimedlock.inl.

Here is the call graph for this function:

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