roo_threads
API Documentation for roo_threads
Loading...
Searching...
No Matches
condition_variable_api.h
Go to the documentation of this file.
1#pragma once
2
4#include "roo_time.h"
5
6namespace roo_threads {
7namespace doc {
8
9/// @ingroup roo_threads_api_condition_variable
10/// @brief Status returned from timed wait operations.
12
13/// @ingroup roo_threads_api_condition_variable
14/// @brief Synchronization primitive for blocking and waking threads.
16 public:
17 /// @brief Constructs a condition variable.
19
21 condition_variable& operator=(const condition_variable&) = delete;
22
23 /// @brief Waits until notified; may wake spuriously.
24 /// @param lock lock associated with the condition variable.
25 void wait(unique_lock<mutex>& lock) noexcept;
26
27 /// @brief Waits until predicate becomes true.
28 /// @param lock lock associated with the condition variable.
29 /// @param pred predicate to evaluate after wakeups.
30 template <class Predicate>
31 void wait(unique_lock<mutex>& lock, Predicate pred);
32
33 /// @brief Wakes one waiting thread.
34 void notify_one() noexcept;
35
36 /// @brief Wakes all waiting threads.
37 void notify_all() noexcept;
38
39 /// @brief Waits until notified or deadline is reached.
40 /// @param lock lock associated with the condition variable.
41 /// @param when absolute timeout point.
42 /// @return timeout status.
43 cv_status wait_until(unique_lock<mutex>& lock, const roo_time::Uptime& when);
44
45 /// @brief Waits until predicate becomes true or deadline is reached.
46 /// @param lock lock associated with the condition variable.
47 /// @param when absolute timeout point.
48 /// @param p predicate to evaluate after wakeups.
49 /// @return true if predicate became true.
50 template <typename Predicate>
51 bool wait_until(unique_lock<mutex>& lock, const roo_time::Uptime& when,
52 Predicate p);
53
54 /// @brief Waits until notified or duration elapses.
55 /// @param lock lock associated with the condition variable.
56 /// @param duration relative timeout duration.
57 /// @return timeout status.
59 const roo_time::Duration& duration);
60
61 /// @brief Waits until predicate becomes true or duration elapses.
62 /// @param lock lock associated with the condition variable.
63 /// @param duration relative timeout duration.
64 /// @param p predicate to evaluate after wakeups.
65 /// @return true if predicate became true.
66 template <typename Predicate>
67 bool wait_for(unique_lock<mutex>& lock, const roo_time::Duration& duration,
68 Predicate p);
69};
70
71} // namespace doc
72} // namespace roo_threads
Synchronization primitive for blocking and waking threads.
condition_variable() noexcept
Constructs a condition variable.
void notify_one() noexcept
Wakes one waiting thread.
void notify_all() noexcept
Wakes all waiting threads.
cv_status wait_for(unique_lock< mutex > &lock, const roo_time::Duration &duration)
Waits until notified or duration elapses.
void wait(unique_lock< mutex > &lock) noexcept
Waits until notified; may wake spuriously.
cv_status wait_until(unique_lock< mutex > &lock, const roo_time::Uptime &when)
Waits until notified or deadline is reached.
Mutual exclusion primitive.
Definition mutex_api.h:12
cv_status
Status returned from timed wait operations.