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"
16#if ALIB_DEBUG && !ALIB_STRINGS
32#if !ALIB_SINGLE_THREADED
55 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
57 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
58 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
61 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
62 if ( waitTimer.
Age() < waitDuration )
66 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
69 std::string msg(
"Waiting to acquire a lock since ");
70 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
84 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
86 if (!
mutex.try_lock() )
106 Ticks::Duration remainingDuration= waitDuration;
108 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
110 remainingDuration= waitDuration - timer.
Age();
111 if ( remainingDuration.IsPositive() )
120 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
122 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
123 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
126 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
127 if ( waitTimer.
Age() < waitDuration )
131 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
134 std::string msg(
"Waiting to acquire a lock since ");
135 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
149 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
151 if (!
mutex.try_lock() )
160 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
162 Ticks::Duration remainingDuration= waitDuration;
164 while (!
mutex.try_lock_for( remainingDuration.Export() ) ) {
165 remainingDuration= waitDuration - timer.
Age();
166 if ( remainingDuration.IsPositive() )
183 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
184 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
187 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
188 if ( waitTimer.
Age() < waitDuration )
192 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
195 std::string msg(
"Waiting to acquire a lock since ");
196 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
209 if (!
mutex.try_lock() )
225 Ticks::Duration remainingDuration= waitDuration;
227 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
229 remainingDuration= waitDuration - timer.
Age();
230 if ( remainingDuration.IsPositive() )
238 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
239 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
242 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
243 if ( waitTimer.
Age() < waitDuration )
247 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
250 std::string msg(
"Waiting to acquire a lock since ");
251 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
265 if (!
mutex.try_lock() )
274 Ticks::Duration remainingDuration= waitDuration;
276 while (!
mutex.try_lock_for( remainingDuration.Export() ) ) {
277 remainingDuration= waitDuration - timer.
Age();
278 if ( remainingDuration.IsPositive() )
296 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
298 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
299 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
302 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
303 if ( waitTimer.
Age() < waitDuration )
307 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
310 std::string msg(
"Waiting to acquire a lock since ");
311 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
325 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
327 if (!
mutex.try_lock() )
342 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
344 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
345 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
348 while (!
mutex.try_lock_shared_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
349 if ( waitTimer.
Age() < waitDuration )
353 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
356 std::string msg(
"Waiting to acquire a lock since ");
357 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
372 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
374 if ( !
mutex.try_lock_shared() )
384 mutex.unlock_shared();
391 Ticks::Duration remainingDuration= waitDuration;
393 while (!
mutex.try_lock_for( remainingDuration.Export() ) )
395 remainingDuration= waitDuration - timer.
Age();
396 if ( remainingDuration.IsPositive() )
404 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
406 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
407 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
410 while (!
mutex.try_lock_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
411 if ( waitTimer.
Age() < waitDuration )
415 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
418 std::string msg(
"Waiting to acquire a lock since ");
419 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
432 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
434 if (!
mutex.try_lock() )
443 Dbg.AssertNotOwning(
ALIB_CALLER, ci,
"Illegal nested acquisition" );
445 Ticks::Duration remainingDuration= waitDuration;
447 while (!
mutex.try_lock_for( remainingDuration.Export() ) ) {
448 remainingDuration= waitDuration - timer.
Age();
449 if ( remainingDuration.IsPositive() )
468 Ticks::Duration remainingDuration= waitDuration;
470 while (!
mutex.try_lock_shared_for( remainingDuration.Export() ) )
472 remainingDuration= waitDuration - timer.
Age();
473 if ( remainingDuration.IsPositive() )
484 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
486 if ( !
Dbg.WaitTimeLimit.IsZero() ) {
487 Ticks::Duration waitDuration=
Dbg.WaitTimeLimit;
490 while (!
mutex.try_lock_shared_for( (waitDuration - waitTimer.
Age()).Export() ) ) {
491 if ( waitTimer.
Age() < waitDuration )
495 NAString msg(
"Waiting to acquire a lock since "); msg << overallTimer.
Age();
498 std::string msg(
"Waiting to acquire a lock since ");
499 msg+= std::format(
"{}", overallTimer.
Age().InAbsoluteMilliseconds());
514 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
516 if ( !
mutex.try_lock_shared() )
526 "AcquireShared while already owning. (This is not allowed with std::shared_lock)" );
528 Ticks::Duration remainingDuration= waitDuration;
530 while (!
mutex.try_lock_shared_for( remainingDuration.Export() ) ) {
531 remainingDuration= waitDuration - timer.
Age();
532 if ( remainingDuration.IsPositive() )
544 mutex.unlock_shared();
549#if ALIB_DEBUG_CRITICAL_SECTIONS
550bool Lock ::DCSIsAcquired ()
const {
return Dbg.IsOwnedByCurrentThread(); }
551bool Lock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
552bool TimedLock ::DCSIsAcquired ()
const {
return Dbg.IsOwnedByCurrentThread(); }
553bool TimedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
554bool RecursiveLock ::DCSIsAcquired ()
const {
return Dbg.IsOwnedByCurrentThread(); }
555bool RecursiveLock ::DCSIsSharedAcquired()
const {
return Dbg.IsOwnedByCurrentThread(); }
558bool SharedLock ::DCSIsAcquired ()
const {
return Dbg.IsOwnedByCurrentThread(); }
559bool SharedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsSharedOwnedByAnyThread()
560 ||
Dbg.IsOwnedByCurrentThread(); }
561bool SharedTimedLock ::DCSIsAcquired ()
const {
return Dbg.IsOwnedByCurrentThread(); }
562bool SharedTimedLock ::DCSIsSharedAcquired()
const {
return Dbg.IsSharedOwnedByAnyThread()
563 ||
Dbg.IsOwnedByCurrentThread(); }
DbgLockAsserter Dbg
The debug tool instance.
ALIB_DLL void Release(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_DLL void Acquire(ALIB_DBG_TAKE_CI)
ALIB_DLL void AcquireRecursive(ALIB_DBG_TAKE_CI)
std::recursive_mutex mutex
ALIB_DLL void ReleaseRecursive(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
DbgLockAsserter Dbg
The debug tool instance.
ALIB_DLL void ReleaseRecursive(ALIB_DBG_TAKE_CI)
DbgLockAsserter Dbg
The debug tool instance.
virtual ALIB_DLL bool DCSIsAcquired() const override
std::recursive_timed_mutex mutex
The internal object to lock on.
virtual ALIB_DLL bool DCSIsSharedAcquired() const override
ALIB_DLL bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
ALIB_DLL void AcquireRecursive(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
std::atomic< int > DbgWarningMaximumShared
ALIB_DLL void Release(ALIB_DBG_TAKE_CI)
DbgSharedLockAsserter Dbg
The debug tool instance.
ALIB_DLL void ReleaseShared(ALIB_DBG_TAKE_CI)
ALIB_DLL void AcquireShared(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquireShared(ALIB_DBG_TAKE_CI)
ALIB_DLL void Acquire(ALIB_DBG_TAKE_CI)
DbgSharedLockAsserter Dbg
The debug tool instance.
std::shared_timed_mutex mutex
The internal object to lock on.
ALIB_DLL void AcquireShared(ALIB_DBG_TAKE_CI)
ALIB_DLL void Acquire(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquireShared(ALIB_DBG_TAKE_CI)
std::atomic< int > DbgWarningMaximumShared
ALIB_DLL void ReleaseShared(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
ALIB_DLL bool TryAcquireSharedTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
ALIB_DLL void Release(ALIB_DBG_TAKE_CI)
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
DbgLockAsserter Dbg
The debug tool instance.
ALIB_DLL bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci)
ALIB_DLL void Release(ALIB_DBG_TAKE_CI)
std::timed_mutex mutex
The internal object to lock on.
ALIB_DLL bool TryAcquire(ALIB_DBG_TAKE_CI)
ALIB_DLL void Acquire(ALIB_DBG_TAKE_CI)
ALIB_DLL Lock STD_IOSTREAMS_LOCK
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
lang::CallerInfo CallerInfo
Type alias in namespace alib.
time::Ticks Ticks
Type alias in namespace alib.