46#ifdef CONFIG_OVE_ZERO_HEAP
47 int err = ove_mutex_init(&handle_, &storage_);
49 int err = ove_mutex_create(&handle_);
51 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
61#ifdef CONFIG_OVE_ZERO_HEAP
62 ove_mutex_deinit(handle_);
64 ove_mutex_destroy(handle_);
71#ifdef CONFIG_OVE_ZERO_HEAP
80 other.handle_ =
nullptr;
90 if (handle_) ove_mutex_destroy(handle_);
91 handle_ = other.handle_;
92 other.handle_ =
nullptr;
104 [[nodiscard]]
int lock(uint32_t timeout_ms = OVE_WAIT_FOREVER) {
105 return ove_mutex_lock(handle_, timeout_ms);
114 ove_mutex_unlock(handle_);
121 bool valid()
const {
return handle_ !=
nullptr; }
127 ove_mutex_t
handle()
const {
return handle_; }
130 ove_mutex_t handle_ =
nullptr;
131#ifdef CONFIG_OVE_ZERO_HEAP
132 ove_mutex_storage_t storage_ = {};
155#ifdef CONFIG_OVE_ZERO_HEAP
156 int err = ove_recursive_mutex_init(&handle_, &storage_);
158 int err = ove_recursive_mutex_create(&handle_);
160 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
167 if (!handle_)
return;
168#ifdef CONFIG_OVE_ZERO_HEAP
169 ove_mutex_deinit(handle_);
171 ove_recursive_mutex_destroy(handle_);
178#ifdef CONFIG_OVE_ZERO_HEAP
187 : handle_(other.handle_) {
188 other.handle_ =
nullptr;
197 if (
this != &other) {
198 if (handle_) ove_recursive_mutex_destroy(handle_);
199 handle_ = other.handle_;
200 other.handle_ =
nullptr;
212 [[nodiscard]]
int lock(uint32_t timeout_ms = OVE_WAIT_FOREVER) {
213 return ove_recursive_mutex_lock(handle_, timeout_ms);
220 ove_recursive_mutex_unlock(handle_);
227 bool valid()
const {
return handle_ !=
nullptr; }
233 ove_mutex_t
handle()
const {
return handle_; }
236 ove_mutex_t handle_ =
nullptr;
237#ifdef CONFIG_OVE_ZERO_HEAP
238 ove_mutex_storage_t storage_ = {};
313 template<
typename... Args>
315 bool expected =
false;
316 if (!initialized_.compare_exchange_strong(expected,
true))
317 OVE_STATIC_INIT_ASSERT(
false &&
"StaticCell already initialized");
318 return *
new (storage_) T(std::forward<Args>(args)...);
329 OVE_STATIC_INIT_ASSERT(initialized_.load());
330 return *
reinterpret_cast<T*
>(storage_);
341 OVE_STATIC_INIT_ASSERT(initialized_.load());
342 return *
reinterpret_cast<const T*
>(storage_);
359 alignas(T) uint8_t storage_[
sizeof(T)]{};
360 std::atomic<bool> initialized_{
false};
387 explicit Semaphore(
unsigned int initial = 0,
unsigned int max = 1) {
388#ifdef CONFIG_OVE_ZERO_HEAP
389 int err = ove_sem_init(&handle_, &storage_, initial, max);
391 int err = ove_sem_create(&handle_, initial, max);
393 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
400 if (!handle_)
return;
401#ifdef CONFIG_OVE_ZERO_HEAP
402 ove_sem_deinit(handle_);
404 ove_sem_destroy(handle_);
411#ifdef CONFIG_OVE_ZERO_HEAP
420 other.handle_ =
nullptr;
429 if (
this != &other) {
430 if (handle_) ove_sem_destroy(handle_);
431 handle_ = other.handle_;
432 other.handle_ =
nullptr;
444 [[nodiscard]]
int take(uint32_t timeout_ms = OVE_WAIT_FOREVER) {
445 return ove_sem_take(handle_, timeout_ms);
454 ove_sem_give(handle_);
461 bool valid()
const {
return handle_ !=
nullptr; }
467 ove_sem_t
handle()
const {
return handle_; }
470 ove_sem_t handle_ =
nullptr;
471#ifdef CONFIG_OVE_ZERO_HEAP
472 ove_sem_storage_t storage_ = {};
495#ifdef CONFIG_OVE_ZERO_HEAP
496 int err = ove_event_init(&handle_, &storage_);
498 int err = ove_event_create(&handle_);
500 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
507 if (!handle_)
return;
508#ifdef CONFIG_OVE_ZERO_HEAP
509 ove_event_deinit(handle_);
511 ove_event_destroy(handle_);
518#ifdef CONFIG_OVE_ZERO_HEAP
527 other.handle_ =
nullptr;
536 if (
this != &other) {
537 if (handle_) ove_event_destroy(handle_);
538 handle_ = other.handle_;
539 other.handle_ =
nullptr;
551 [[nodiscard]]
int wait(uint32_t timeout_ms = OVE_WAIT_FOREVER) {
552 return ove_event_wait(handle_, timeout_ms);
559 ove_event_signal(handle_);
568 ove_event_signal_from_isr(handle_);
575 bool valid()
const {
return handle_ !=
nullptr; }
581 ove_event_t
handle()
const {
return handle_; }
584 ove_event_t handle_ =
nullptr;
585#ifdef CONFIG_OVE_ZERO_HEAP
586 ove_event_storage_t storage_ = {};
611#ifdef CONFIG_OVE_ZERO_HEAP
612 int err = ove_condvar_init(&handle_, &storage_);
614 int err = ove_condvar_create(&handle_);
616 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
623 if (!handle_)
return;
624#ifdef CONFIG_OVE_ZERO_HEAP
625 ove_condvar_deinit(handle_);
627 ove_condvar_destroy(handle_);
634#ifdef CONFIG_OVE_ZERO_HEAP
643 other.handle_ =
nullptr;
652 if (
this != &other) {
653 if (handle_) ove_condvar_destroy(handle_);
654 handle_ = other.handle_;
655 other.handle_ =
nullptr;
674 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
675 return ove_condvar_wait(handle_, mtx.
handle(), timeout_ms);
682 ove_condvar_signal(handle_);
689 ove_condvar_broadcast(handle_);
696 bool valid()
const {
return handle_ !=
nullptr; }
702 ove_condvar_t
handle()
const {
return handle_; }
705 ove_condvar_t handle_ =
nullptr;
706#ifdef CONFIG_OVE_ZERO_HEAP
707 ove_condvar_storage_t storage_ = {};
RAII wrapper around an oveRTOS condition variable.
Definition sync.hpp:603
int wait(Mutex &mtx, uint32_t timeout_ms=OVE_WAIT_FOREVER)
Atomically releases the mutex and waits for a notification.
Definition sync.hpp:673
CondVar & operator=(CondVar &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition sync.hpp:651
~CondVar()
Destroys the condition variable, releasing the underlying kernel resource.
Definition sync.hpp:622
void signal()
Wakes one task waiting on this condition variable.
Definition sync.hpp:681
CondVar()
Constructs and initialises the condition variable.
Definition sync.hpp:610
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition sync.hpp:696
CondVar(CondVar &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition sync.hpp:642
ove_condvar_t handle() const
Returns the raw oveRTOS condition variable handle.
Definition sync.hpp:702
void broadcast()
Wakes all tasks waiting on this condition variable.
Definition sync.hpp:688
RAII wrapper around an oveRTOS binary event flag.
Definition sync.hpp:487
ove_event_t handle() const
Returns the raw oveRTOS event handle.
Definition sync.hpp:581
void signal_from_isr()
Signals the event from an ISR context, waking any blocked waiter.
Definition sync.hpp:567
Event(Event &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition sync.hpp:526
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition sync.hpp:575
int wait(uint32_t timeout_ms=OVE_WAIT_FOREVER)
Blocks the calling task until the event is signalled or the timeout expires.
Definition sync.hpp:551
~Event()
Destroys the event, releasing the underlying kernel resource.
Definition sync.hpp:506
Event()
Constructs and initialises the event in the unsignalled state.
Definition sync.hpp:494
Event & operator=(Event &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition sync.hpp:535
void signal()
Signals the event from task context, waking any blocked waiter.
Definition sync.hpp:558
Scoped RAII guard that locks a Mutex on construction and unlocks it on destruction.
Definition sync.hpp:252
LockGuard(Mutex &mtx)
Constructs the guard, immediately locking the given mutex.
Definition sync.hpp:258
~LockGuard()
Destroys the guard, unlocking the associated mutex.
Definition sync.hpp:266
RAII wrapper around an oveRTOS non-recursive mutex.
Definition sync.hpp:37
Mutex(Mutex &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition sync.hpp:79
ove_mutex_t handle() const
Returns the raw oveRTOS mutex handle.
Definition sync.hpp:127
int lock(uint32_t timeout_ms=OVE_WAIT_FOREVER)
Acquires the mutex, blocking until it is available or the timeout expires.
Definition sync.hpp:104
Mutex()
Constructs and initialises the mutex.
Definition sync.hpp:45
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition sync.hpp:121
~Mutex()
Destroys the mutex, releasing the underlying kernel resource.
Definition sync.hpp:59
void unlock()
Releases the mutex.
Definition sync.hpp:113
Mutex & operator=(Mutex &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition sync.hpp:88
RAII wrapper around an oveRTOS recursive mutex.
Definition sync.hpp:146
RecursiveMutex(RecursiveMutex &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition sync.hpp:186
RecursiveMutex()
Constructs and initialises the recursive mutex.
Definition sync.hpp:154
void unlock()
Releases one level of the recursive lock.
Definition sync.hpp:219
int lock(uint32_t timeout_ms=OVE_WAIT_FOREVER)
Acquires the recursive mutex.
Definition sync.hpp:212
RecursiveMutex & operator=(RecursiveMutex &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition sync.hpp:196
~RecursiveMutex()
Destroys the recursive mutex, releasing the underlying kernel resource.
Definition sync.hpp:166
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition sync.hpp:227
ove_mutex_t handle() const
Returns the raw oveRTOS mutex handle.
Definition sync.hpp:233
RAII wrapper around an oveRTOS counting semaphore.
Definition sync.hpp:378
void give()
Increments the semaphore count, unblocking a waiting task if any.
Definition sync.hpp:453
ove_sem_t handle() const
Returns the raw oveRTOS semaphore handle.
Definition sync.hpp:467
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition sync.hpp:461
Semaphore & operator=(Semaphore &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition sync.hpp:428
int take(uint32_t timeout_ms=OVE_WAIT_FOREVER)
Decrements the semaphore count, blocking if the count is zero.
Definition sync.hpp:444
Semaphore(Semaphore &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition sync.hpp:419
~Semaphore()
Destroys the semaphore, releasing the underlying kernel resource.
Definition sync.hpp:399
Semaphore(unsigned int initial=0, unsigned int max=1)
Constructs and initialises the semaphore.
Definition sync.hpp:387
Thread-safe, lazily initialised storage cell for a single object of type T.
Definition sync.hpp:301
bool is_initialized() const
Returns true if init() has been called successfully.
Definition sync.hpp:349
T & init(Args &&... args)
Constructs the contained object in-place.
Definition sync.hpp:314
const T & get() const
Returns a const reference to the contained object.
Definition sync.hpp:340
T & get()
Returns a reference to the contained object.
Definition sync.hpp:328
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.