MOTION
0.01
Framework for mixed-protocol multi-party computation
|
Go to the documentation of this file.
27 #include <condition_variable>
43 Condition(
const std::function<
bool()> condition_function)
44 : condition_function_(condition_function) {}
48 std::scoped_lock lock(mutex_);
49 return condition_function_();
58 template <
typename Tick,
typename Period>
59 bool WaitFor(std::chrono::duration<Tick, Period> duration) {
60 std::unique_lock<std::mutex> lock(mutex_);
61 condition_variable_.wait_for(lock, duration, condition_function_);
62 return condition_function_();
66 void NotifyOne() noexcept { condition_variable_.notify_one(); }
69 void NotifyAll() noexcept { condition_variable_.notify_all(); }
74 std::mutex&
GetMutex() noexcept {
return mutex_; }
77 std::condition_variable condition_variable_;
79 const std::function<bool()> condition_function_;
bool Wait()
Blocks until thread is notified and condition_function_ returns true.
Definition: condition.cpp:29
void NotifyOne() noexcept
Unblocks one thread waiting for condition_variable_.
Definition: condition.h:66
std::mutex & GetMutex() noexcept
Get the mutex.
Definition: condition.h:74
Definition: algorithm_description.cpp:35
bool WaitFor(std::chrono::duration< Tick, Period > duration)
Blocks until thread is notified and condition_function_ returns true or duration time has passed.
Definition: condition.h:59
bool operator()()
checks if the condition was satisfied
Definition: condition.h:47
Wraps a std::condition_variable with a std::mutex and a condition checking function.
Definition: condition.h:35
void NotifyAll() noexcept
Unblocks all threads waiting for condition_variable_.
Definition: condition.h:69
Condition(const std::function< bool()> condition_function)
Registers the condition function that encapsulates the condition checking.
Definition: condition.h:43