10#ifndef STK_SYNC_SEMAPHORE_H_
11#define STK_SYNC_SEMAPHORE_H_
61 explicit Semaphore(uint16_t initial_count = 0U, uint16_t max_count = 0xFFFEU)
128 __stk_full_memfence();
158 __stk_full_memfence();
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Implementation of synchronization primitive: stk::sync::ScopedCriticalSection.
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...
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
Synchronization primitives for task coordination and resource protection.
virtual bool IsTimeout() const =0
Check if task woke up due to a timeout.
IWaitObject::ListHeadType m_wait_list
tasks blocked on this object
void WakeOne()
Wake the first task in the wait list (FIFO order).
ISyncObject()
Constructor.
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual IWaitObject * Wait(ISyncObject *sobj, IMutex *mutex, Timeout timeout)=0
Put calling process into a waiting state until synchronization object is signaled or timeout occurs.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
void Signal()
Post a signal (increment counter).
uint16_t m_count_max
Counter max limit.
STK_NONCOPYABLE_CLASS(Semaphore)
Semaphore(uint16_t initial_count=0U, uint16_t max_count=0xFFFEU)
Constructor.
uint16_t m_count
Internal resource counter.
bool Wait(Timeout timeout=WAIT_INFINITE)
Wait for a signal (decrement counter).
uint16_t GetCount() const
Get current counter value.
bool TryWait()
Poll the semaphore without blocking (decrement counter if available).