ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
dbgasserters.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
15#include "alib/alib.inl"
16// =========================================== Module ==========================================
17#if ALIB_C20_MODULES
18 module ALib.Threads;
19 import ALib.Lang;
20#else
21# include "ALib.Lang.H"
22# include "ALib.Threads.H"
23# include "ALib.Strings.H"
24#endif
25// ====================================== Implementation =======================================
26#if !ALIB_SINGLE_THREADED && ALIB_DEBUG
27
28namespace alib::threads {
29
30// #################################################################################################
31// Class DbgLockAsserter
32// #################################################################################################
34{
35 if ( CntAcquirements == 0 )
36 return nullptr;
37 return Thread::Get(AcqCI.ThreadID);
38}
39
41"Multi-Threadding {} in Lock \"{}\"" "\n"
42" Message: {}" "\n"
43" In (Member-)Function: {}" "\n"
44" Is Owned: {} ({})" "\n"
45 "\n"
46" Called By: {}::{}" "\n"
47" At: {}:{}" "\n"
48" Thread: {}" "\n"
49 "\n"
50" Latest Acquisition By: {}::{}" "\n"
51" At: {}:{}" "\n"
52" Thread: {}" "\n"
53" Latest Release By: {}:{}" "\n"
54" At: {}:{}" "\n"
55" Thread: {}" "\n"
56;
57
59"Multi-Threadding {} in Shared-Lock \"{}\"" "\n"
60" Message: {}" "\n"
61" In (Member-)Function: {}" "\n"
62" Is Owned: {} ({})" "\n"
63" Is Shared Owned: {} ({})" "\n"
64 "\n"
65" Called By: {}::{}" "\n"
66" At: {}:{}" "\n"
67" Thread: {}" "\n"
68 "\n"
69" Latest Acquisition By: {}::{}" "\n"
70" At: {}:{}" "\n"
71" Thread: {}" "\n"
72" Latest Release By: {}::{}" "\n"
73" At: {}:{}" "\n"
74" Thread: {}" "\n"
75 "\n"
76" Latest Shared Acquisition By: {}::{}" "\n"
77" At: {}:{}" "\n"
78" Thread: {}" "\n"
79" Latest SharedRelease By: {}::{}" "\n"
80" At: {}:{}" "\n"
81" Thread: {}" "\n"
82;
83
84
85void DbgLockAsserter::DoAssert( int type, const CallerInfo& ciAssert, const CallerInfo& ci,
86 const char* headline )
87{
88 assert::Raise( ciAssert, type, "THREADS", ASSERTION_FORMAT,
89 (type== 0 ? "Assertion" : "Warning"), // 0
90 Name , headline, // 1 2
91 ciAssert.Func, // 3
92 (CntAcquirements>0 ? "true" : "false"), // 4
93 CntAcquirements, // 5
94
95 ci.TypeInfo, ci.Func, ci.File, ci.Line, ci.ThreadID,
96 AcqCI.TypeInfo, AcqCI.Func, AcqCI.File, AcqCI.Line, AcqCI.ThreadID,
97 RelCI.TypeInfo, RelCI.Func, RelCI.File, RelCI.Line, RelCI.ThreadID );
98 }
99
100void DbgSharedLockAsserter::DoAssert( int type, const CallerInfo& ciAssert, const CallerInfo& ci,
101 const char* headline )
102{
103 assert::Raise( ciAssert, type, "THREADS", ASSERTION_FORMAT_SHARED,
104 (type== 0 ? "Assertion" : "Warning"), // 0
105 Name , headline, // 1 2
106 ciAssert.Func, // 3
109
110 ci.TypeInfo, ci.Func, ci.File, ci.Line, ci.ThreadID,
111 AcqCI.TypeInfo, AcqCI.Func, AcqCI.File, AcqCI.Line, AcqCI.ThreadID,
112 RelCI.TypeInfo, RelCI.Func, RelCI.File, RelCI.Line, RelCI.ThreadID,
113 SAcqCI.TypeInfo, SAcqCI.Func, SAcqCI.File, SAcqCI.Line, SAcqCI.ThreadID,
114 SRelCI.TypeInfo, SRelCI.Func, SRelCI.File, SRelCI.Line, SRelCI.ThreadID
115 );
116}
117
119"Assertion failed in method TCondition::{}" "\n"
120" Message: {}" "\n"
121" Instance: {}" "\n"
122 "\n"
123" Called By: {}::{}" "\n"
124" At: {}:{}" "\n"
125" Thread: {}" "\n"
126 "\n"
127" Current Owner: {}" "\n"
128" #Of Waiters: {}" "\n"
129" Exclusive Waiter: {}" "\n"
130 "\n"
131" Latest Acquisition By: {}::{}" "\n"
132" At: {}:{}" "\n"
133" Thread: {}" "\n"
134" Latest Release By: {}::{}" "\n"
135" At: {}:{}" "\n"
136" Thread: {}" "\n"
137 "\n"
138" Latest Wait By: {}::{}" "\n"
139" At: {}:{}" "\n"
140" Thread: {}" "\n"
141" Latest Notify By: {}::{}" "\n"
142" At: {}:{}" "\n"
143" Thread: {}" "\n"
144;
145
146void DbgConditionAsserter::Assert( bool cond, const CallerInfo& ciAssert, const CallerInfo& ci,
147 const char* headline )
148{
149 if (cond)
150 return;
151 assert::Raise( ciAssert, 0, "THREADS", ASSERTION_FORMAT,
152 ciAssert.Func, headline, Name,
153 ci.TypeInfo, ci.Func, ci.File, ci.Line, ci.ThreadID,
155
156 AcqCI.TypeInfo, AcqCI.Func, AcqCI.File, AcqCI.Line, AcqCI.ThreadID,
157 RelCI.TypeInfo, RelCI.Func, RelCI.File, RelCI.Line, RelCI.ThreadID,
158 WaitCI.TypeInfo, WaitCI.Func, WaitCI.File, WaitCI.Line, WaitCI.ThreadID,
159 NotifyCI.TypeInfo, NotifyCI.Func, NotifyCI.File, NotifyCI.Line, NotifyCI.ThreadID );
160
161}
162
163
164} // namespace [alib::threads]
165
166#endif // !ALIB_SINGLE_THREADED && ALIB_DEBUG
static ALIB_DLL Thread * Get(std::thread::id nativeID)
Definition thread.cpp:329
void Raise(const lang::CallerInfo &ci, int type, std::string_view domain, TArgs &&... args)
Definition assert.inl:181
lang::CallerInfo CallerInfo
Type alias in namespace alib.
const char * File
The name of the source file as given by compiler.
const std::type_info * TypeInfo
The calling type.
int Line
The line number within File.
std::thread::id ThreadID
The ID of the calling thread.
ALIB_DLL void Assert(bool cond, const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
CallerInfo NotifyCI
The most recent call to ReleaseAndNotify or.
const character * Name
The name of this instance.
static ALIB_DLL const char * ASSERTION_FORMAT
CallerInfo RelCI
Source location of the most recent release.
Thread * Owner
Tracks the current owner.
std::atomic< int > CntWaiters
The number of currently waiting threads.
CallerInfo AcqCI
Source location of the most recent acquirement.
CallerInfo WaitCI
The most recent call to WaitForNotification.
static ALIB_DLL const char * ASSERTION_FORMAT
CallerInfo RelCI
Source location of the most recent release.
int16_t CntAcquirements
The number of nested acquirements.
virtual ALIB_DLL void DoAssert(int type, const CallerInfo &assertCI, const CallerInfo &ci, const char *headline)
ALIB_DLL Thread * GetOwner() const
CallerInfo AcqCI
Source location of the most recent acquirement.
CallerInfo SAcqCI
Source location of the most recent shared acquirement.
ALIB_DLL void DoAssert(int type, const CallerInfo &assertCI, const CallerInfo &ci, const char *headline) override
static ALIB_DLL const char * ASSERTION_FORMAT_SHARED
std::atomic< int > CntSharedAcquirements
The number of shared acquirements.
CallerInfo SRelCI
Source location of the most recent shared release.