A condition variable exactly similar to the one in libcxx with two major differences:
More...
#include <thread.h>
|
| ConditionVariable ()=default |
|
| ~ConditionVariable ()=default |
|
| ConditionVariable (const ConditionVariable &)=delete |
|
ConditionVariable & | operator= (const ConditionVariable &)=delete |
|
void | NotifyOne () |
|
void | NotifyAll () |
|
template<class Clock , class Duration > |
bool | WaitUntil (Mutex &mutex, const std::chrono::time_point< Clock, Duration > &time_point, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex) |
| Atomically unlocks the mutex and waits on the condition variable up to a specified time point. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false for the wait to continue. The predicate will be invoked with the mutex locked. More...
|
|
template<class Representation , class Period > |
bool | WaitFor (Mutex &mutex, const std::chrono::duration< Representation, Period > &duration, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex) |
| Atomically unlocks the mutex and waits on the condition variable for a designated duration. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false for the wait to continue. The predicate will be invoked with the mutex locked. More...
|
|
void | Wait (Mutex &mutex, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex) |
| Atomically unlocks the mutex and waits on the condition variable indefinitely till the predicate determines that the wait must end. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false for the wait to continue. The predicate will be invoked with the mutex locked. More...
|
|
A condition variable exactly similar to the one in libcxx with two major differences:
- On the Wait, WaitFor, and WaitUntil calls, static analysis annotation are respected.
- There is no ability to wait on a condition variable and also be susceptible to spurious wakes. This is because the predicate is mandatory.
Definition at line 144 of file thread.h.
◆ Predicate
◆ ConditionVariable() [1/2]
impeller::ConditionVariable::ConditionVariable |
( |
| ) |
|
|
default |
◆ ~ConditionVariable()
impeller::ConditionVariable::~ConditionVariable |
( |
| ) |
|
|
default |
◆ ConditionVariable() [2/2]
◆ NotifyAll()
void impeller::ConditionVariable::NotifyAll |
( |
| ) |
|
|
inline |
◆ NotifyOne()
void impeller::ConditionVariable::NotifyOne |
( |
| ) |
|
|
inline |
◆ operator=()
◆ Wait()
void impeller::ConditionVariable::Wait |
( |
Mutex & |
mutex, |
|
|
const Predicate & |
should_stop_waiting |
|
) |
| |
|
inline |
Atomically unlocks the mutex and waits on the condition variable indefinitely till the predicate determines that the wait must end. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false
for the wait to continue. The predicate will be invoked with the mutex locked.
- Note
- Since the predicate is invoked with the mutex locked, if it accesses other guarded resources, the predicate itself must be decorated with the IPLR_REQUIRES directive. For instance,
```c++ [] () IPLR_REQUIRES(mutex) { return my_guarded_resource.should_stop_waiting; } ```
- Parameters
-
| mutex | The mutex |
[in] | should_stop_waiting | The should stop waiting |
Definition at line 258 of file thread.h.
259 {
260 std::unique_lock lock(mutex.mutex_, std::adopt_lock);
261 cv_.wait(lock, should_stop_waiting);
262 lock.release();
263 }
◆ WaitFor()
template<class Representation , class Period >
bool impeller::ConditionVariable::WaitFor |
( |
Mutex & |
mutex, |
|
|
const std::chrono::duration< Representation, Period > & |
duration, |
|
|
const Predicate & |
should_stop_waiting |
|
) |
| |
|
inline |
Atomically unlocks the mutex and waits on the condition variable for a designated duration. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false
for the wait to continue. The predicate will be invoked with the mutex locked.
- Note
- Since the predicate is invoked with the mutex locked, if it accesses other guarded resources, the predicate itself must be decorated with the IPLR_REQUIRES directive. For instance,
```c++ [] () IPLR_REQUIRES(mutex) { return my_guarded_resource.should_stop_waiting; } ```
- Parameters
-
| mutex | The mutex. |
[in] | duration | The duration to wait for. |
[in] | should_stop_waiting | The predicate invoked on spurious wakes. Must return false for the wait to continue. |
- Template Parameters
-
Representation | The duration representation type. |
Period | The duration period type. |
- Returns
- The value of the predicate at the end of the wait.
Definition at line 229 of file thread.h.
231 {
233 should_stop_waiting);
234 }
bool WaitUntil(Mutex &mutex, const std::chrono::time_point< Clock, Duration > &time_point, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable up to a specified time point....
◆ WaitUntil()
template<class
Clock , class Duration >
bool impeller::ConditionVariable::WaitUntil |
( |
Mutex & |
mutex, |
|
|
const std::chrono::time_point< Clock, Duration > & |
time_point, |
|
|
const Predicate & |
should_stop_waiting |
|
) |
| |
|
inline |
Atomically unlocks the mutex and waits on the condition variable up to a specified time point. Lock will be reacquired when the wait exits. Spurious wakes may happen before the time point is reached. In such cases the predicate is invoked and it must return false
for the wait to continue. The predicate will be invoked with the mutex locked.
- Note
- Since the predicate is invoked with the mutex locked, if it accesses other guarded resources, the predicate itself must be decorated with the IPLR_REQUIRES directive. For instance,
```c++ [] () IPLR_REQUIRES(mutex) { return my_guarded_resource.should_stop_waiting; } ```
- Parameters
-
| mutex | The mutex. |
[in] | time_point | The time point to wait to. |
[in] | should_stop_waiting | The predicate invoked on spurious wakes. Must return false for the wait to continue. |
- Template Parameters
-
Clock | The clock type. |
Duration | The duration type. |
- Returns
- The value of the predicate at the end of the wait.
Definition at line 190 of file thread.h.
192 {
193 std::unique_lock lock(mutex.mutex_, std::adopt_lock);
194 const auto result = cv_.wait_until(lock, time_point, should_stop_waiting);
195 lock.release();
197 }
The documentation for this class was generated from the following file: