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

Description:

This type is used for debugging and asserting ALib lock (mutex) types. With debug compilations the non-shared lock types hold one member of this struct, which aggregates all debug information.

Definition at line 17 of file dbgasserters.inl.

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

Public Static Field Index:

static ALIB_DLL const char * ASSERTION_FORMAT
 

Public Field Index:

CallerInfo AcqCI
 Source location of the most recent acquirement.
 
int16_t CntAcquirements = 0
 The number of nested acquirements.
 
const char * Name ="<unnamed>"
 
int RecursionLimit =10
 
CallerInfo RelCI
 Source location of the most recent release.
 
Ticks::Duration WaitTimeLimit = Ticks::Duration::FromAbsoluteSeconds(2)
 

Public Method Index:

virtual ~DbgLockAsserter ()
 Destructor.
 
void AssertNotOwned (const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
void AssertNotOwnedOrMe (const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
void AssertNotOwning (const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
void AssertOwned (const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
void AssertOwning (const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
virtual ALIB_DLL void DoAssert (int type, const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
 
ALIB_DLL ThreadGetOwner () const
 
bool IsOwnedByCurrentThread () const
 
bool WillRelease () const noexcept
 

Field Details:

◆ AcqCI

CallerInfo alib::threads::DbgLockAsserter::AcqCI

Source location of the most recent acquirement.

Definition at line 24 of file dbgasserters.inl.

◆ ASSERTION_FORMAT

const char * alib::threads::DbgLockAsserter::ASSERTION_FORMAT
static
Initial value:
=
"Multi-Threadding {} in Lock \"{}\"" "\n"
" Message: {}" "\n"
" In (Member-)Function: {}" "\n"
" Is Owned: {} ({})" "\n"
"\n"
" Called By: {}::{}" "\n"
" At: {}:{}" "\n"
" Thread: {}" "\n"
"\n"
" Latest Acquisition By: {}::{}" "\n"
" At: {}:{}" "\n"
" Thread: {}" "\n"
" Latest Release By: {}:{}" "\n"
" At: {}:{}" "\n"
" Thread: {}" "\n"

The format string used to write exceptions to the console. This string can be changed if the source information is not "clickable" in a user's development environment.

The default string is optimized for JetBrains CLion and is defined as:

Multi-Threadding {} in Lock \"{}\"
                Message: {}
   In (Member-)Function: {}
               Is Owned: {} ({})

              Called By: {}::{}
                     At: {}:{}
                 Thread: {}

  Latest Acquisition By: {}::{}
                     At: {}:{}
                 Thread: {}
      Latest Release By: {}:{}
                     At: {}:{}
                 Thread: {}

The placeholder fields that this format string refers to are set as follows:

  • 0: String "Assertion" or "Warning"
  • 1: Debug-name of the lock.
  • 2: Headline.
  • 3: Function name.
  • 4: Is acquired (true/false).
  • 5: number of acquirements.
  • 6-10: CallerInfo of caller.
  • 11-15: CallerInfo of the latest acquisition.
  • 16-20: CallerInfo of the latest release.

Definition at line 64 of file dbgasserters.inl.

◆ CntAcquirements

int16_t alib::threads::DbgLockAsserter::CntAcquirements = 0

The number of nested acquirements.

Definition at line 26 of file dbgasserters.inl.

◆ Name

const char* alib::threads::DbgLockAsserter::Name ="<unnamed>"

The name of this Lock. Set to "<unnamed>" by default. Used for debug-output. For automatic pruning of changes to this name, macro ALIB_DBG should be used.

Definition at line 23 of file dbgasserters.inl.

◆ RecursionLimit

int alib::threads::DbgLockAsserter::RecursionLimit =10

Limit of recursions. If the limit is reached or a multiple of it, an ALib warning is raised. Defaults is 10. To disable, set to 0.

Available only in debug versions of ALib.

Definition at line 78 of file dbgasserters.inl.

◆ RelCI

CallerInfo alib::threads::DbgLockAsserter::RelCI

Source location of the most recent release.

Definition at line 25 of file dbgasserters.inl.

◆ WaitTimeLimit

Ticks::Duration alib::threads::DbgLockAsserter::WaitTimeLimit = Ticks::Duration::FromAbsoluteSeconds(2)

This is a threshold that causes non-timed Acquire() methods to raise a ALib warning in debug-builds in case a thread is blocked longer than the given duration.

To disable warnings in cases that high block times are suitable, set this value to 0. The default value is two seconds.

Definition at line 72 of file dbgasserters.inl.

Constructor(s) / Destructor Details:

◆ ~DbgLockAsserter()

virtual alib::threads::DbgLockAsserter::~DbgLockAsserter ( )
inlinevirtual

Destructor.

Definition at line 81 of file dbgasserters.inl.

Method Details:

◆ AssertNotOwned()

void alib::threads::DbgLockAsserter::AssertNotOwned ( const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
inline

Asserts that CntAcquirements is 0

Parameters
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Definition at line 135 of file dbgasserters.inl.

Here is the call graph for this function:

◆ AssertNotOwnedOrMe()

void alib::threads::DbgLockAsserter::AssertNotOwnedOrMe ( const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
inline

Asserts that either CntAcquirements is 0 or the lock is owned by calling thread.

Parameters
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Definition at line 145 of file dbgasserters.inl.

Here is the call graph for this function:

◆ AssertNotOwning()

void alib::threads::DbgLockAsserter::AssertNotOwning ( const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
inline

Asserts that this lock is not owned by the thread in ci.

Parameters
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Definition at line 165 of file dbgasserters.inl.

Here is the call graph for this function:

◆ AssertOwned()

void alib::threads::DbgLockAsserter::AssertOwned ( const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
inline

Asserts that CntAcquirements is not 0

Parameters
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Definition at line 125 of file dbgasserters.inl.

Here is the call graph for this function:

◆ AssertOwning()

void alib::threads::DbgLockAsserter::AssertOwning ( const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
inline

Asserts that this lock is owned by the thread in ci.

Parameters
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Definition at line 155 of file dbgasserters.inl.

Here is the call graph for this function:

◆ DoAssert()

void alib::threads::DbgLockAsserter::DoAssert ( int type,
const CallerInfo & assertCI,
const CallerInfo & ci,
const char * headline )
virtual

Collects assertion info and raises a warning or error.

See also
Field ASSERTION_FORMAT which allows changing the output format to achieve 'clickable' assertion messages.
Parameters
type0= assertion, 1= warning.
assertCILocation where the assertion is placed.
ciLocation of the call to the method that asserted.
headlineThe message.

Reimplemented in alib::threads::DbgSharedLockAsserter.

Definition at line 85 of file dbgasserters.cpp.

Here is the call graph for this function:

◆ GetOwner()

Thread * alib::threads::DbgLockAsserter::GetOwner ( ) const

Returns a pointer the owning thread.

Available only in debug-builds.

Returns
Pointer to the owning thread, or nullptr if not owned.

Definition at line 33 of file dbgasserters.cpp.

Here is the call graph for this function:

◆ IsOwnedByCurrentThread()

bool alib::threads::DbgLockAsserter::IsOwnedByCurrentThread ( ) const
inline

Returns true if the current owner is the current thread.

Available only in debug-builds.

Returns
true, if the lock is owned by this thread, false if it is owned by another thread or not owned.

Definition at line 93 of file dbgasserters.inl.

◆ WillRelease()

bool alib::threads::DbgLockAsserter::WillRelease ( ) const
inlinenoexcept

Returns true if this is a non-recursive lock or a recursive instance which is acquired exactly once.
Available only in debug-builds.

Note
This method is not (and cannot) be synchronized. Consequently, a reliable result is only guaranteed in case IsOwnedByCurrentThread returns true before this method is invoked.
Returns
true if the next release will free this lock, false otherwise.

Definition at line 106 of file dbgasserters.inl.


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