12#include <stk_config.h>
20inline void *
operator new(std::size_t,
void *ptr)
noexcept {
return ptr; }
21inline void operator delete(
void *,
void *)
noexcept { }
102 lock->~stk_spinlock_t();
325 return ef->
handle.
Wait(flags, options, timeout);
418 rw->~stk_rwmutex_t();
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Collection of synchronization primitives (stk::sync namespace).
C language binding/interface for SuperTinyKernel (STK).
Pipe< stk_word_t, STK_PIPE_SIZE > PipeX
void stk_event_set(stk_event_t *ev)
Set the event to signaled state.
void stk_sem_signal(stk_sem_t *sem)
Signal/Release a semaphore resource.
uint32_t stk_ef_set(stk_ef_t *ef, uint32_t flags)
Set one or more flags.
stk_spinlock_t * stk_spinlock_create(stk_spinlock_mem_t *memory, uint32_t memory_size)
Create a recursive SpinLock.
uint32_t stk_ef_clear(stk_ef_t *ef, uint32_t flags)
Clear one or more flags.
void stk_mutex_destroy(stk_mutex_t *mtx)
Destroy a Mutex.
bool stk_rwmutex_try_read_lock(stk_rwmutex_t *rw)
Try to acquire the read lock without blocking.
stk_ef_t * stk_ef_create(stk_ef_mem_t *memory, uint32_t memory_size, uint32_t initial_flags)
Create an EventFlags object (using provided memory).
bool stk_spinlock_trylock(stk_spinlock_t *lock)
Attempt to acquire the SpinLock immediately.
void stk_ef_destroy(stk_ef_t *ef)
Destroy an EventFlags object.
void stk_event_reset(stk_event_t *ev)
Reset the event to non-signaled state.
bool stk_rwmutex_trylock(stk_rwmutex_t *rw)
Try to acquire the write lock without blocking.
struct stk_ef_t stk_ef_t
Opaque handle to an EventFlags instance.
stk_pipe_t * stk_pipe_create(stk_pipe_mem_t *memory, uint32_t memory_size)
Create a Pipe (using provided memory).
bool stk_pipe_read(stk_pipe_t *pipe, stk_word_t *data, int32_t timeout)
Read data from the pipe.
uint32_t stk_ef_trywait(stk_ef_t *ef, uint32_t flags, uint32_t options)
Non-blocking flag poll.
void stk_cv_notify_one(stk_cv_t *cv)
Wake one task waiting on the condition variable.
bool stk_rwmutex_timed_lock(stk_rwmutex_t *rw, int32_t timeout)
Try to acquire the write lock with a timeout.
bool stk_rwmutex_timed_read_lock(stk_rwmutex_t *rw, int32_t timeout)
Try to acquire the read lock with a timeout.
bool stk_event_trywait(stk_event_t *ev)
Wait for the event to become signaled.
uint32_t stk_ef_wait(stk_ef_t *ef, uint32_t flags, uint32_t options, int32_t timeout)
Wait for one or more flags to be set.
void stk_event_destroy(stk_event_t *ev)
Destroy an Event.
stk_rwmutex_t * stk_rwmutex_create(stk_rwmutex_mem_t *memory, uint32_t memory_size)
Create an RWMutex (using provided memory).
void stk_mutex_lock(stk_mutex_t *mtx)
Lock the mutex. Blocks until available.
void stk_rwmutex_lock(stk_rwmutex_t *rw)
Acquire the lock for exclusive writing. Blocks until available.
stk_sem_t * stk_sem_create(stk_sem_mem_t *memory, uint32_t memory_size, uint32_t initial_count)
Create a Semaphore (using provided memory).
void stk_cv_destroy(stk_cv_t *cv)
Destroy a Condition Variable.
struct stk_event_t stk_event_t
Opaque handle to an Event instance.
size_t stk_pipe_get_size(stk_pipe_t *pipe)
Get current number of elements in the pipe.
void stk_spinlock_unlock(stk_spinlock_t *lock)
Release the SpinLock.
bool stk_mutex_trylock(stk_mutex_t *mtx)
Try locking the mutex. Does not block if already locked.
void stk_rwmutex_read_lock(stk_rwmutex_t *rw)
Acquire the lock for shared reading. Blocks until available.
stk_mutex_t * stk_mutex_create(stk_mutex_mem_t *memory, uint32_t memory_size)
Create a Mutex (using provided memory).
struct stk_sem_t stk_sem_t
Opaque handle to a Semaphore instance.
void stk_mutex_unlock(stk_mutex_t *mtx)
Unlock the mutex.
void stk_pipe_destroy(stk_pipe_t *pipe)
Destroy a Pipe.
void stk_spinlock_destroy(stk_spinlock_t *lock)
Destroy the SpinLock.
stk_cv_t * stk_cv_create(stk_cv_mem_t *memory, uint32_t memory_size)
Create a Condition Variable (using provided memory).
bool stk_sem_wait(stk_sem_t *sem, int32_t timeout)
Wait for a semaphore resource.
size_t stk_pipe_read_bulk(stk_pipe_t *pipe, stk_word_t *dst, size_t count, int32_t timeout)
Read multiple elements from the pipe.
struct stk_spinlock_t stk_spinlock_t
Opaque handle to a SpinLock instance.
void stk_spinlock_lock(stk_spinlock_t *lock)
Acquire the SpinLock (recursive).
void stk_sem_destroy(stk_sem_t *sem)
Destroy a Semaphore.
stk_event_t * stk_event_create(stk_event_mem_t *memory, uint32_t memory_size, bool manual_reset)
Create an Event (using provided memory).
void stk_rwmutex_read_unlock(stk_rwmutex_t *rw)
Release the shared reader lock.
uint32_t stk_ef_get(stk_ef_t *ef)
Read the current flags word without modifying it.
bool stk_cv_wait(stk_cv_t *cv, stk_mutex_t *mtx, int32_t timeout)
Wait for a signal on the condition variable.
void stk_event_pulse(stk_event_t *ev)
Pulse the event (signal then immediately reset).
size_t stk_pipe_write_bulk(stk_pipe_t *pipe, const stk_word_t *src, size_t count, int32_t timeout)
Write multiple elements to the pipe.
uintptr_t stk_word_t
CPU register type.
void stk_rwmutex_destroy(stk_rwmutex_t *rw)
Destroy an RWMutex.
bool stk_pipe_write(stk_pipe_t *pipe, stk_word_t data, int32_t timeout)
Write data to the pipe.
bool stk_event_wait(stk_event_t *ev, int32_t timeout)
Wait for the event to become signaled.
void stk_cv_notify_all(stk_cv_t *cv)
Wake all tasks waiting on the condition variable.
bool stk_mutex_timed_lock(stk_mutex_t *mtx, int32_t timeout)
Try to lock the mutex with a timeout.
void stk_rwmutex_unlock(stk_rwmutex_t *rw)
Release the exclusive writer lock.
Namespace of STK package.
Synchronization primitives for task coordination and resource protection.
Condition Variable primitive for signaling between tasks based on specific predicates.
bool Wait(IMutex &mutex, Timeout timeout=WAIT_INFINITE)
Wait for a signal.
void NotifyOne()
Wake one waiting task.
void NotifyAll()
Wake all waiting tasks.
Binary synchronization event (signaled / non-signaled) primitive.
bool Set()
Set event to signaled state.
void Pulse()
Pulse event: attempt to release waiters and then reset (Win32 PulseEvent() semantics).
bool TryWait()
Poll event state without blocking.
bool Reset()
Reset event to non-signaled state.
bool Wait(Timeout timeout=WAIT_INFINITE)
Wait until event becomes signaled or the timeout expires.
32-bit event flags group for multi-flag synchronization between tasks.
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout=WAIT_INFINITE)
Wait for one or more flags to be set.
uint32_t Get() const
Read the current flags word without modifying it.
uint32_t TryWait(uint32_t flags, uint32_t options=OPT_WAIT_ANY)
Non-blocking flag poll.
uint32_t Clear(uint32_t flags)
Clear one or more flags.
uint32_t Set(uint32_t flags)
Set one or more flags.
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
void Unlock()
Release lock.
bool TryLock()
Acquire the lock.
bool TimedLock(Timeout timeout)
Acquire lock.
Thread-safe FIFO communication pipe for inter-task data passing.
size_t GetSize() const
Get the current number of elements in the pipe.
size_t WriteBulk(const T *src, size_t count, Timeout timeout=WAIT_INFINITE)
Write multiple elements to the pipe.
bool Write(const T &data, Timeout timeout=WAIT_INFINITE)
Write data to the pipe.
bool Read(T &data, Timeout timeout=WAIT_INFINITE)
Read data from the pipe.
size_t ReadBulk(T *dst, size_t count, Timeout timeout=WAIT_INFINITE)
Read multiple elements from the pipe.
Reader-Writer Lock synchronization primitive for non-recursive shared and exclusive access.
bool TryLock()
Attempt to acquire the lock for exclusive writing without blocking.
bool TimedReadLock(Timeout timeout)
Acquire the lock for shared reading with a timeout.
void Lock()
Acquire the lock for exclusive writing (IMutex interface).
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.
Counting semaphore primitive for resource management and signaling.
void Signal()
Post a signal (increment counter).
bool Wait(Timeout timeout=WAIT_INFINITE)
Wait for a signal (decrement counter).
void Unlock()
Release the lock or decrement the recursion counter.
bool TryLock()
Attempt to acquire the lock without blocking.
void Lock()
Acquire the lock.
Opaque memory container for a Mutex instance.
stk_word_t data[(10+((0) ? 1 :0))]
Opaque memory container for SpinLock object.
Opaque memory container for a ConditionVariable instance.
stk_word_t data[(7+((0) ? 1 :0))]
Opaque memory container for an Event instance.
stk_word_t data[(8+((0) ? 1 :0))]
Opaque memory container for a Semaphore instance.
stk_word_t data[(8+((0) ? 1 :0))]
Opaque memory container for an EventFlags instance.
stk_word_t data[((7+((0) ? 1 :0))+1+((0) ? 1 :0))]
Opaque memory container for a Pipe instance.
stk_word_t data[((27+((0) ? 3 :0))+16)]
Opaque memory container for an RWMutex instance.
stk_word_t data[(17+((0) ? 3 :0))]
stk_event_t(bool manual_reset)
stk_sem_t(uint32_t initial_count)
stk_ef_t(uint32_t initial_flags)