13#include <condition_variable>
15#include "AUI/Performance/APerformanceSection.h"
26 std::condition_variable_any mImpl;
31 std::unique_lock lock(thread->mCurrentCV.mutex);
33 thread->mCurrentCV.cv = &var;
35 ~WaitHelper()
noexcept(
false) {
37 std::unique_lock lock(thread->mCurrentCV.mutex);
38 thread->mCurrentCV.cv =
nullptr;
42 template<
typename Predicate>
43 struct PredicateHelper {
47 PredicateHelper(Predicate predicate) : predicate(std::move(predicate)), thread(
AThread::current()) {}
48 bool operator()()
noexcept {
49 if (thread->isInterrupted())
return true;
73 template<
typename Lock>
74 void wait(Lock& lock) {
88 template<
typename Lock,
typename Predicate>
89 void wait(Lock& lock, Predicate&& predicate) {
93 mImpl.wait(lock, PredicateHelper(std::forward<Predicate>(predicate)));
103 template<
typename Lock,
typename Duration>
108 mImpl.wait_for(lock, duration);
119 template<
typename Lock,
typename Duration,
typename Predicate>
120 void wait_for(Lock& lock, Duration duration, Predicate&& predicate) {
124 mImpl.wait_for(lock, duration, PredicateHelper(std::forward<Predicate>(predicate)));
134 template<
typename Lock,
typename Timepo
int>
139 mImpl.wait_until(lock, timepoint);
150 template<
typename Lock,
typename Duration,
typename Predicate>
151 void wait_until(Lock& lock, Duration duration, Predicate&& predicate) {
155 mImpl.wait_until(lock, duration, PredicateHelper(std::forward<Predicate>(predicate)));
Represents a condition variable.
Definition: AConditionVariable.h:24
void notify_one() noexcept
Definition: AConditionVariable.h:71
void wait_until(Lock &lock, Duration duration, Predicate &&predicate)
Definition: AConditionVariable.h:151
void wait_until(Lock &lock, Timepoint timepoint)
Definition: AConditionVariable.h:135
void wait(Lock &lock, Predicate &&predicate)
Definition: AConditionVariable.h:89
void wait_for(Lock &lock, Duration duration, Predicate &&predicate)
Definition: AConditionVariable.h:120
void notify_all() noexcept
Definition: AConditionVariable.h:62
void wait_for(Lock &lock, Duration duration)
Definition: AConditionVariable.h:104
static _< AAbstractThread > current()
Definition: AThread.cpp:221
static void interruptionPoint()
Interruption point.
Definition: AThread.cpp:232
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177