8#if !ALIB_SINGLE_THREADED
77template<
typename TDerived>
88 TDerived&
cast() {
return static_cast<TDerived&
>(*this); }
122 "Acquire: Multiple acquirements of TCondition are forbidden." );
129 "Acquire: Owner is (still) set, after std::mutex.lock()." );
146 "Release: Ownership is with a different thread" );
165 "ReleaseAndNotify called without prior acquisition" );
168 "ReleaseAndNotify: Ownership is with a different thread" );
185 "An exclusive waiter is set. Thus, notifying 'all' is not allowed.");
188 "ReleaseAndNotify called without prior acquisition" );
191 "ReleaseAndNotify: Ownership is with a different thread" );
213 ||
Dbg.AssertExclusiveWaiter == std::this_thread::get_id(),
ALIB_CALLER, ci,
214 "WaitForNotification called by a different thread than granted with 'Dbg.AssertExclusiveWaiter'.");
217 "WaitForNotification called without prior acquisition" );
220 "WaitForNotification: Ownership is with a different thread" );
227 std::unique_lock<std::mutex> lock(
mutex, std::adopt_lock);
250 ||
Dbg.AssertExclusiveWaiter == std::this_thread::get_id(),
ALIB_CALLER, ci,
251 "WaitForNotification called by a different thread than granted with 'Dbg.AssertExclusiveWaiter'.");
254 "WaitForNotification called without prior acquisition" );
257 "WaitForNotification: Ownership is with a different thread" );
264 std::unique_lock<std::mutex> lock(
mutex, std::adopt_lock);
301 ||
Dbg.AssertExclusiveWaiter == std::this_thread::get_id(),
ALIB_CALLER, ci,
302 "WaitForNotification called by a different thread than granted with 'Dbg.AssertExclusiveWaiter'.");
305 "WaitForNotification called without prior acquisition" );
308 "WaitForNotification: Ownership is with a different thread" );
316 std::unique_lock<std::mutex> lock(
mutex, std::adopt_lock);
318 [
this]{ return cast().isConditionMet(); } );
404 void Wait(
const Ticks::Duration::TDuration& maxWaitTimeSpan,
const CallerInfo& ci ) {
411 void Wait(
const Ticks::Duration::TDuration& maxWaitTimeSpan )
414 WaitForNotification(maxWaitTimeSpan);
430 {
Wait( maxWaitTimeSpan.Export(), ci ); }
432 void Wait(
const Ticks::Duration& maxWaitTimeSpan )
433 { Wait( maxWaitTimeSpan.Export() ); }
453 void Wait(
const Ticks& wakeUpTime )
456 WaitForNotification(wakeUpTime);
464template<
typename T=
bool>
Condition(const character *dbgName)
void Notify(ALIB_DBG_TAKE_CI)
bool notified
Boolean member which records notifications. Defaults to not-notified.
void NotifyAll(ALIB_DBG_TAKE_CI)
void Wait(const Ticks::Duration::TDuration &maxWaitTimeSpan, const CallerInfo &ci)
void Wait(const Ticks &wakeUpTime, const CallerInfo &ci)
void Wait(const Ticks::Duration &maxWaitTimeSpan, const CallerInfo &ci)
void Wait(ALIB_DBG_TAKE_CI)
static Thread * GetCurrent()
static ALIB_DLL Thread * Get(std::thread::id nativeID)
TTimePoint Export() const
constexpr bool IsNotNull(const T &t)
constexpr bool IsNull(const T &t)
threads::TCondition< T > TCondition
Type alias in namespace alib.
lang::CallerInfo CallerInfo
Type alias in namespace alib.
time::Ticks Ticks
Type alias in namespace alib.
threads::Condition Condition
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
std::thread::id ThreadID
The ID of the calling thread.
void WaitForNotification(ALIB_DBG_TAKE_CI)
void ReleaseAndNotifyAll(ALIB_DBG_TAKE_CI)
TCondition(const character *dbgName)
std::condition_variable conditionVariable
void Release(ALIB_DBG_TAKE_CI)
void Acquire(ALIB_DBG_TAKE_CI)
void WaitForNotification(const Ticks::Duration &maxWaitTimeSpan, const CallerInfo &ci)
void WaitForNotification(const Ticks::Duration::TDuration &maxWaitTimeSpan, const CallerInfo &ci)
void ReleaseAndNotify(ALIB_DBG_TAKE_CI)