10#ifndef STK_SYNC_RWMUTEX_H_
11#define STK_SYNC_RWMUTEX_H_
#define STK_KERNEL_PANIC(id)
Called when the kernel detects an unrecoverable internal fault.
Contains interface definitions of the library.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Implementation of synchronization primitive: stk::sync::ScopedCriticalSection.
Implementation of synchronization primitive: stk::sync::ConditionVariable.
Namespace of STK package.
const Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
int32_t Timeout
Timeout time (ticks).
const Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
@ KERNEL_PANIC_ASSERT
Internal assertion failed (maps from STK_ASSERT).
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
Synchronization primitives for task coordination and resource protection.
Interface for mutex synchronization primitive.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Condition Variable primitive for signaling between tasks based on specific predicates.
static const uint16_t READERS_MAX
maximum number of concurrent readers
bool TryLock()
Attempt to acquire the lock for exclusive writing without blocking.
ConditionVariable m_cv_writers
signaled when a writer can proceed
bool m_writer_active
true if a writer currently holds the lock
static const uint16_t WRITERS_MAX
maximum number of waiting writers
uint16_t m_writers_waiting
count of writers waiting for access
uint16_t m_readers
current active reader count
bool TimedReadLock(Timeout timeout)
Acquire the lock for shared reading with a timeout.
RWMutex()
Construct an RWMutex in the unlocked state with no active readers or writers.
void Lock()
Acquire the lock for exclusive writing (IMutex interface).
STK_NONCOPYABLE_CLASS(RWMutex)
ConditionVariable m_cv_readers
signaled when readers can proceed
void ReadUnlock()
Release the shared reader lock.
void ReadLock()
Acquire the lock for shared reading.
void Unlock()
Release the exclusive writer lock (IMutex interface).
bool TryReadLock()
Attempt to acquire the lock for shared reading without blocking.
bool TimedLock(Timeout timeout)
Acquire the lock for exclusive writing with a timeout.
STK_NONCOPYABLE_CLASS(ScopedTimedLock)
ScopedTimedLock(RWMutex &rw, Timeout timeout=WAIT_INFINITE)
Constructs the guard and attempts to acquire the write lock.
STK_NONCOPYABLE_CLASS(ScopedTimedReadMutex)
ScopedTimedReadMutex(RWMutex &rw, Timeout timeout=WAIT_INFINITE)
Constructs the guard and attempts to acquire the read lock.