|
oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
|
RAII wrapper around an oveRTOS condition variable. More...
#include <sync.hpp>
Public Member Functions | |
| CondVar () | |
| Constructs and initialises the condition variable. | |
| ~CondVar () noexcept | |
| Destroys the condition variable, releasing the underlying kernel resource. | |
| CondVar (const CondVar &)=delete | |
| CondVar & | operator= (const CondVar &)=delete |
| CondVar (CondVar &&other) noexcept | |
| Move constructor — transfers ownership of the kernel handle. | |
| CondVar & | operator= (CondVar &&other) noexcept |
| Move-assignment operator — transfers ownership of the kernel handle. | |
| void | wait (Mutex &mtx) |
| Atomically releases the mutex and waits for a notification. | |
| template<class Rep , class Period > | |
| Result< void > | try_wait_for (Mutex &mtx, const std::chrono::duration< Rep, Period > &rel) noexcept |
| Bounded-wait. | |
| template<class Clock , class Duration > | |
| Result< void > | try_wait_until (Mutex &mtx, const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
| Deadline-based wait templated over the clock. | |
| template<typename Predicate > | |
| void | wait (Mutex &mtx, Predicate pred) |
Predicate-loop wait. std::condition_variable::wait predicate-overload analog. | |
| template<typename Rep , typename Period , typename Predicate > | |
| bool | try_wait_for (Mutex &mtx, std::chrono::duration< Rep, Period > rel, Predicate pred) |
Bounded-wait with predicate. std::condition_variable::wait_for predicate-overload analog. | |
| template<typename Clock , typename Duration , typename Predicate > | |
| bool | try_wait_until (Mutex &mtx, const std::chrono::time_point< Clock, Duration > &deadline, Predicate pred) |
Deadline-based wait with predicate. std::condition_variable::wait_until predicate-overload analog. | |
| void | notify_one () |
Wakes one task waiting on this condition variable. std::condition_variable::notify_one analog. | |
| void | notify_all () |
Wakes all tasks waiting on this condition variable. std::condition_variable::notify_all analog. | |
| bool | valid () const |
Returns true if the underlying kernel handle is non-null. | |
| ove_condvar_t | handle () const |
| Returns the raw oveRTOS condition variable handle. | |
RAII wrapper around an oveRTOS condition variable.
A condition variable allows tasks to efficiently wait for a predicate to become true. It must always be used together with a Mutex — the mutex is atomically released while waiting and re-acquired before wait() returns.
wait() to guard against spurious wake-ups.
|
inline |
Constructs and initialises the condition variable.
Asserts at startup if initialisation fails.
|
inlinenoexcept |
Move constructor — transfers ownership of the kernel handle.
| other | The source; its handle is set to null after the move. |
Move-assignment operator — transfers ownership of the kernel handle.
| other | The source; its handle is set to null after the move. |
|
inline |
Atomically releases the mutex and waits for a notification.
The calling task must hold mtx before calling this method. The mutex is released atomically while the task blocks, and re-acquired before the call returns.
Forever wait; failure means the handle is unusable. Aborts via OVE_STATIC_INIT_ASSERT. Always re-check the predicate after wait returns to guard against spurious wake-ups.
std::condition_variable::wait analog.
| [in] | mtx | The mutex associated with the predicate being waited on. Must be locked by the calling thread. |
|
inlinenoexcept |
Bounded-wait.
Loose analog of std::condition_variable::wait_for — but returns Result<void> rather than std::cv_status, matching the Result-shape convention used by the rest of the ove::Mutex/Semaphore/Event timeout-bearing methods.
(std::cv_status is unavailable on the bare-metal backends — arm-gnu-toolchain's libstdc++ ships with --enable-threads=single, so neither std::condition_variable nor std::cv_status are declared. Using Result<void> keeps the API uniform across POSIX, FreeRTOS, NuttX and Zephyr.)
| [in] | mtx | The mutex (locked by the calling thread). The kernel releases it while blocking and re-acquires it before returning. |
| [in] | rel | Relative timeout (any std::chrono::duration unit). |
Result<void> on wake; unexpected Error::Timeout if the deadline elapsed without a notification; unexpected with another Error value on backend failure.try_wait() immediate form — a condvar wait is inherently blocking; std::condition_variable matches this (no try_wait).
|
inlinenoexcept |
Deadline-based wait templated over the clock.
Same clock-templating rationale as Mutex::try_lock_until.
Result<void> with Error::Timeout on timeout.
|
inline |
Predicate-loop wait. std::condition_variable::wait predicate-overload analog.
Equivalent to:
Handles spurious wake-ups internally; caller cannot accidentally write the if (cv.wait(...) == OVE_OK && ready) { ... } race-prone form.
| [in] | mtx | The mutex (locked by the calling thread). |
| [in] | pred | Callable returning bool. Evaluated under mtx. |
|
inline |
Bounded-wait with predicate. std::condition_variable::wait_for predicate-overload analog.
Loops on pred, returning when either pred() becomes true or rel elapses.
true if pred() was true on return; false if the timeout elapsed with pred() still false.
|
inline |
Deadline-based wait with predicate. std::condition_variable::wait_until predicate-overload analog.
Loops on pred, recomputing the remaining timeout on each iteration so spurious wake-ups don't shorten the effective deadline.
true if pred() was true on return; false if the deadline elapsed with pred() still false.
|
inline |
Returns true if the underlying kernel handle is non-null.
true when the condition variable was successfully initialised.
|
inline |
Returns the raw oveRTOS condition variable handle.
ove_condvar_t handle.