ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
dbgcriticalsections.cpp
1
2#if ALIB_DEBUG_CRITICAL_SECTIONS
3namespace alib::lang {
4
6
7
9"Assertion in Critical Section \"{}\"" "\n"
10" Message: {}" "\n"
11" In (Member-)Function: {}" "\n"
12" Is Owned: {} ({})" "\n"
13" Is Shared Owned: {} ({})" "\n"
14 "\n"
15" Called By: {}::{}" "\n"
16" At: {}:{}" "\n"
17" Thread: {}" "\n"
18 "\n"
19" Latest Acquisition By: {}::{}" "\n"
20" At: {}:{}" "\n"
21" Thread: {}" "\n"
22" Latest Release By: {}::{}" "\n"
23" At: {}:{}" "\n"
24" Thread: {}" "\n"
25 "\n"
26" Latest Shared Acquisition By: {}::{}" "\n"
27" At: {}:{}" "\n"
28" Thread: {}" "\n"
29" Latest SharedRelease By: {}::{}" "\n"
30" At: {}:{}" "\n"
31" Thread: {}" "\n"
32;
33
34void DbgCriticalSections::doAssert( bool cond, const CallerInfo& ciAssert, const CallerInfo& ci,
35 const char* headline ) const {
36 if (cond) return;
37
38 assert::Raise( ciAssert, 0, "THREADS", ASSERTION_FORMAT,
39 DCSName, headline, ciAssert.Func,
40 DCSWriterCnt.load() > 0, DCSWriterCnt.load(),
41 DCSReaderCnt.load() > 0, DCSReaderCnt.load(),
42 ci.TypeInfo, ci.Func, ci.File, ci.Line, ci.ThreadID,
43 DCSAcq.TypeInfo, DCSAcq.Func, DCSAcq.File, DCSAcq.Line, DCSAcq.ThreadID,
44 DCSRel.TypeInfo, DCSRel.Func, DCSRel.File, DCSRel.Line, DCSRel.ThreadID,
45 DCSSAcq.TypeInfo,DCSSAcq.Func,DCSSAcq.File,DCSSAcq.Line,DCSSAcq.ThreadID,
46 DCSSRel.TypeInfo,DCSSRel.Func,DCSSRel.File,DCSSRel.Line,DCSSRel.ThreadID );
47}
48
50 doAssert( !DCSLock || DCSLock->DCSIsAcquired(), ALIB_CALLER, ci, "Acquire: Associated Lock not acquired." );
51 doAssert( DCSWriterCnt.load() == 0
52 || DCSAcq.ThreadID == std::this_thread::get_id(), ALIB_CALLER, ci, "Acquired by other thread.");
53 doAssert( DCSReaderCnt.load() == 0, ALIB_CALLER, ci, "Acquired by reader.");
54
55 DCSWriterCnt.fetch_add(1);
56 DCSAcq= ci;
58}
59
61 doAssert(!DCSLock || DCSLock->DCSIsAcquired() , ALIB_CALLER, ci, "Release: Associated lock not acquired." );
62 doAssert(DCSAcq.ThreadID == std::this_thread::get_id(), ALIB_CALLER, ci, "Release: Acquired by other thread.");
64 DCSRel= ci;
65 DCSWriterCnt.fetch_sub(1);
66}
67
69 doAssert( !DCSLock || DCSLock->DCSIsSharedAcquired(), ALIB_CALLER, ci,
70 "AcquireShared: Associated lock not shared-acquired." );
71
73 int wCnt = DCSWriterCnt.load();
74 doAssert(wCnt <= 0 || DCSAcq.ThreadID == std::this_thread::get_id(), ALIB_CALLER, ci,
75 "AcquireShared: Acquired by different thread.");
76 DCSReaderCnt.fetch_add(1);
77 DCSSAcq= ci;
78}
79
82 doAssert( !DCSLock || DCSLock->DCSIsSharedAcquired(), ALIB_CALLER, ci,
83 "ReleaseShared: Associated lock not shared-acquired." );
84
85 doAssert(DCSWriterCnt.load() <= 0 || DCSAcq.ThreadID == std::this_thread::get_id(), ALIB_CALLER, ci,
86 "ReleaseShared: Internal error. Acquired by different thread while shared release.");
87 int prevRCnt= DCSReaderCnt.fetch_sub(1);
88 doAssert(prevRCnt > 0, ALIB_CALLER, ci, "ReleaseShared: No shared acquirement.");
89 DCSSRel= ci;
90}
91
92} // namespace [alib::lang]
93
94#endif // ALIB_DEBUG_CRITICAL_SECTIONS
#define ALIB_CALLER
void Raise(const lang::CallerInfo &ci, int type, std::string_view domain, TArgs &&... args)
Definition assert.hpp:178
unsigned DBG_CRITICAL_SECTION_YIELD_OR_SLEEP_TIME_IN_NS
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.
CallerInfo DCSSRel
Source location of the last "reader" seen.
void Acquire(const CallerInfo &ci) const
void doAssert(bool cond, const CallerInfo &ciAssert, const CallerInfo &ci, const char *headline) const
CallerInfo DCSRel
Source location of the last "reader" seen.
const char * DCSName
The name of this DCS. Used for debug-output.
CallerInfo DCSSAcq
Source location of acquirement.
CallerInfo DCSAcq
Source location of acquirement.
void Release(const CallerInfo &ci) const
void AcquireShared(const CallerInfo &ci) const
std::atomic< int > DCSReaderCnt
Tracks enter/exit calls of readers.
void ReleaseShared(const CallerInfo &ci) const
std::atomic< int > DCSWriterCnt
Tracks enter/exit calls (including readers).