37namespace alib {
namespace threads {
50#if ALIB_CAMP && !DOXYGEN
52"Multi-Threadding {} in Lock {!Q}" "\n"
54" In (Member-)Function: {:ya}" "\n"
57" Called By: {4:ya}" "\n"
61" Latest Acquisition By: {5:ya}" "\n"
64" Latest Release By: {6:ya}" "\n"
70"Multi-Threadding {} in Lock {!Q}" "\n"
72" In (Member-)Function: {:ya}" "\n"
74" Is Shared Owned: {10}" "\n"
76" Called By: {4:ya}" "\n"
80" Latest Acquisition By: {5:ya}" "\n"
83" Latest Release By: {6:ya}" "\n"
87" Latest Shared Acquisition By: {8:ya}" "\n"
90" Latest SharedRelease By: {9:ya}" "\n"
103 msg << (type== 0 ?
"Assertion" :
"Warning")
104 <<
" with Mutex/Locking in " <<
Name <<
"\n"
105 " Message: " << headline <<
"\n"
106 " Caller: " << ci <<
"\n"
108 " Latest Acquirement: " <<
AcqCI <<
"\n"
109 " Latest Release: " <<
RelCI <<
"\n\n"
110 "Note: Include ALib module BaseCamp in the ALib-Distribution to get nicer assertion output.\n";
117 (type== 0 ?
"Assertion" :
"Warning"),
134 DbgSimpleALibMsg( ciAssert, type,
"THREADS", nmsg );
148 msg << (type== 0 ?
"Assertion" :
"Warning")
149 <<
" with Mutex/Locking in " <<
Name <<
"\n"
150 " Message: " << headline <<
"\n"
151 " Caller: " << ci <<
"\n"
154 " Latest Acquirement: " <<
AcqCI <<
"\n"
155 " Latest Release: " <<
RelCI <<
"\n\n"
156 " Latest Shared Acquirement: " <<
SAcqCI <<
"\n"
157 " Latest Shared Release: " <<
SRelCI <<
"\n\n"
158 "Note: Include ALib module BaseCamp in the ALib-Distribution to get nicer assertion output.\n";
167 (type== 0 ?
"Assertion" :
"Warning"),
184 DbgSimpleALibMsg( ciAssert, type,
"THREADS", nmsg );
193#if ALIB_CAMP && !DOXYGEN
195"Assertion failed in method TCondition::{2:sm}" "\n"
199" Called By: {3:ya}" "\n"
201" Thread: {3:ta}" "\n"
203" Current Owner: {4}" "\n"
204" #Of Waiters: {5}" "\n"
205" Exclusive Waiter: {6}" "\n"
207" Latest Acquisition By: {7:ya}" "\n"
209" Thread: {7:ta}" "\n"
210" Latest Release By: {8:ya}" "\n"
212" Thread: {8:ta}" "\n"
214" Latest Wait By: {9:ya}" "\n"
216" Thread: {9:ta}" "\n"
217" Latest Notify By: {10:ya}" "\n"
218" At: {10:sf:sl}" "\n"
219" Thread: {10:ta}" "\n"
231 msg <<
"Assertion failed in method TCondition::" << ciAssert.
Func <<
"()\n"
232 " Message: " << headline <<
"\n"
234 " Caller: " << ci <<
"\n\n"
235 " Current Owner: " <<
Owner <<
"\n"
238 " Most Recent Acquirement: " <<
AcqCI <<
"\n"
239 " Most Recent Release: " <<
RelCI <<
"\n"
240 " Most Recent Wait: " <<
WaitCI <<
"\n"
241 " Most Recent Notify: " <<
NotifyCI <<
"\n"
242 "Note: Include ALib module BaseCamp in the ALib-Distribution to get nicer assertion output.\n";
264 DbgSimpleALibMsg( ciAssert, 0,
"THREADS", nmsg );
273#if ALIB_DEBUG_CRITICAL_SECTIONS
274bool Lock ::DCSIsAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
275bool Lock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
276bool TimedLock ::DCSIsAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
277bool TimedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
278bool RecursiveLock ::DCSIsAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
279bool RecursiveLock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
282bool SharedLock ::DCSIsAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
283bool SharedTimedLock ::DCSIsAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
284bool SharedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsSharedOwnedByAnyThread()
285 || Dbg.IsOwnedByCurrentThread(); }
286bool SharedTimedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsSharedOwnedByAnyThread()
287 || Dbg.IsOwnedByCurrentThread(); }
321 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
323 if ( waitTimer.
Age() < waitDuration )
327 msg <<
"Waiting to acquire a lock since "
329 << overallTimer.
Age();
350 if (!
mutex.try_lock() )
378 Ticks::Duration remainingDuration= waitDuration;
380 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
382 remainingDuration= waitDuration - timer.
Age();
383 if ( remainingDuration.IsPositive() )
400 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
402 if ( waitTimer.
Age() < waitDuration )
406 msg <<
"Waiting to acquire a lock since "
408 << overallTimer.
Age();
429 if (!
mutex.try_lock() )
444 Ticks::Duration remainingDuration= waitDuration;
446 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
448 remainingDuration= waitDuration - timer.
Age();
449 if ( remainingDuration.IsPositive() )
485 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
487 if ( waitTimer.
Age() < waitDuration )
491 msg <<
"Waiting to acquire a lock since "
493 << overallTimer.
Age();
511 " Warning limit can be adopted with field DbgRecursionWarningThreshold" );
516 if (!
mutex.try_lock() )
526 " Warning limit can be adopted with field DbgRecursionWarningThreshold" );
549 Ticks::Duration remainingDuration= waitDuration;
551 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
553 remainingDuration= waitDuration - timer.
Age();
554 if ( remainingDuration.IsPositive() )
568 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
570 if ( waitTimer.
Age() < waitDuration )
574 msg <<
"Waiting to acquire a lock since "
576 << overallTimer.
Age();
594 " Warning limit can be adopted with field DbgRecursionWarningThreshold" );
599 if (!
mutex.try_lock() )
609 " Warning limit can be adopted with field DbgRecursionWarningThreshold" );
616 Ticks::Duration remainingDuration= waitDuration;
618 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
620 remainingDuration= waitDuration - timer.
Age();
621 if ( remainingDuration.IsPositive() )
633 " Warning limit can be adopted with field DbgRecursionWarningThreshold" );
662 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
664 if ( waitTimer.
Age() < waitDuration )
668 msg <<
"Waiting to acquire a lock since "
670 << overallTimer.
Age();
691 if (!
mutex.try_lock() )
716 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
723 while (!
mutex.try_lock_shared_for( (waitDuration - waitTimer.
Age()).Export() ) )
725 if ( waitTimer.
Age() < waitDuration )
729 msg <<
"Waiting to acquire a lock since "
731 << overallTimer.
Age();
745 "Too many parallel shared acquisitions detected. "
746 "A reason might be that shared acquirers do not call ReleaseShared" );
754 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
756 if ( !
mutex.try_lock_shared() )
762 "Too many parallel shared acquisitions detected. "
763 "A reason might be that shared acquirers do not call ReleaseShared" );
772 if ( prevCounter <= 0 )
774 "Too many invocations of ReleaseShared (from any thread) without prior acquisition" );
777 mutex.unlock_shared();
789 Ticks::Duration remainingDuration= waitDuration;
791 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
793 remainingDuration= waitDuration - timer.
Age();
794 if ( remainingDuration.IsPositive() )
810 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) )
812 if ( waitTimer.
Age() < waitDuration )
816 msg <<
"Waiting to acquire a lock since "
818 << overallTimer.
Age();
838 if (!
mutex.try_lock() )
852 Ticks::Duration remainingDuration= waitDuration;
854 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
856 remainingDuration= waitDuration - timer.
Age();
857 if ( remainingDuration.IsPositive() )
885 Ticks::Duration remainingDuration= waitDuration;
887 while (!
mutex.try_lock_shared_for( remainingDuration.Export() ) )
889 remainingDuration= waitDuration - timer.
Age();
890 if ( remainingDuration.IsPositive() )
902 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
909 while (!
mutex.try_lock_shared_for( (waitDuration - waitTimer.
Age()).Export() ) )
911 if ( waitTimer.
Age() < waitDuration )
915 msg <<
"Waiting to acquire a lock since "
917 << overallTimer.
Age();
933 "Too many parallel shared acquisitions detected. "
934 "A reason might be that shared acquirers do not call ReleaseShared" );
942 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
944 if ( !
mutex.try_lock_shared() )
951 "Too many parallel shared acquisitions detected. "
952 "A reason might be that shared acquirers do not call ReleaseShared" );
962 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
964 Ticks::Duration remainingDuration= waitDuration;
966 while (!
mutex.try_lock_shared_for( remainingDuration.Export() ) )
968 remainingDuration= waitDuration - timer.
Age();
969 if ( remainingDuration.IsPositive() )
978 "Too many parallel shared acquisitions detected. "
979 "A reason might be that shared acquirers do not call ReleaseShared" );
988 if ( prevCounter <= 0 )
990 "Too many invocations of ReleaseShared (from any thread) without prior acquisition" );
993 mutex.unlock_shared();
static ALIB_API textlogger::TextLogger * DebugLogger
The debug logger created by AddDebugLogger.
FormatMultiLine & GetFormatMultiLine()
DbgLockAsserter Dbg
The debug tool instance.
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_API void Acquire(ALIB_DBG_TAKE_CI)
ALIB_API void Release(ALIB_DBG_TAKE_CI)
DbgLockAsserter Dbg
The debug tool instance.
ALIB_API void AcquireRecursive(ALIB_DBG_TAKE_CI)
std::recursive_mutex mutex
ALIB_API void ReleaseRecursive(ALIB_DBG_TAKE_CI)
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
virtual ALIB_API bool DCSIsAcquired() const override
ALIB_API bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
DbgLockAsserter Dbg
The debug tool instance.
virtual ALIB_API bool DCSIsSharedAcquired() const override
ALIB_API void AcquireRecursive(ALIB_DBG_TAKE_CI)
ALIB_API void ReleaseRecursive(ALIB_DBG_TAKE_CI)
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
std::recursive_timed_mutex mutex
The internal object to lock on.
ALIB_API bool TryAcquireShared(ALIB_DBG_TAKE_CI)
ALIB_API void AcquireShared(ALIB_DBG_TAKE_CI)
DbgSharedLockAsserter Dbg
The debug tool instance.
ALIB_API void ReleaseShared(ALIB_DBG_TAKE_CI)
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_API void Acquire(ALIB_DBG_TAKE_CI)
ALIB_API void Release(ALIB_DBG_TAKE_CI)
std::atomic< int > DbgWarningMaximumShared
ALIB_API bool TryAcquireShared(ALIB_DBG_TAKE_CI)
ALIB_API bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
ALIB_API void AcquireShared(ALIB_DBG_TAKE_CI)
DbgSharedLockAsserter Dbg
The debug tool instance.
ALIB_API bool TryAcquireSharedTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
std::shared_timed_mutex mutex
The internal object to lock on.
ALIB_API void ReleaseShared(ALIB_DBG_TAKE_CI)
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_API void Acquire(ALIB_DBG_TAKE_CI)
ALIB_API void Release(ALIB_DBG_TAKE_CI)
std::atomic< int > DbgWarningMaximumShared
static ALIB_API Thread * Get(std::thread::id nativeID)
ALIB_API bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
std::timed_mutex mutex
The internal object to lock on.
DbgLockAsserter Dbg
The debug tool instance.
ALIB_API bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_API void Acquire(ALIB_DBG_TAKE_CI)
ALIB_API void Release(ALIB_DBG_TAKE_CI)
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
ALIB_API Lock STD_IOSTREAMS_LOCK
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
lang::integer integer
Type alias in namespace alib.
std::thread::id ThreadID
The ID of the calling thread.
CallerInfo WaitCI
The most recent call to WaitForNotification.
CallerInfo AcqCI
Source location of the most recent acquirement.
CallerInfo RelCI
Source location of the most recent release.
std::thread::id AssertExclusiveWaiter
CallerInfo NotifyCI
The most recent call to ReleaseAndNotify or.
ALIB_API void Assert(bool cond, const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
String Name
The name of this instance.
static ALIB_API NString ASSERTION_FORMAT
std::atomic< int > CntWaiters
The number of currently waiting threads.
Thread * Owner
Tracks the current owner.
ALIB_API Thread * GetOwner() const
int16_t CntAcquirements
The number of nested acquirements.
void AssertNotOwned(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
void AssertNotOwning(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
bool IsOwnedByCurrentThread() const
CallerInfo AcqCI
Source location of the most recent acquirement.
void AssertNotOwnedOrMe(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
CallerInfo RelCI
Source location of the most recent release.
void AssertOwning(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
virtual ALIB_API void DoAssert(int type, const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
Ticks::Duration WaitTimeLimit
static ALIB_API NString ASSERTION_FORMAT
void AssertOwned(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
void AssertNotOwned(const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline)
std::atomic< int > CntSharedAcquirements
The number of shared acquirements.
CallerInfo SAcqCI
Source location of the most recent shared acquirement.
ALIB_API void DoAssert(int type, const CallerInfo &assertCI, const CallerInfo &ci, const NString &headline) override
CallerInfo SRelCI
Source location of the most recent shared release.
static ALIB_API NString ASSERTION_FORMAT_SHARED