10#ifndef STK_SYNC_EVENT_FLAGS_H_
11#define STK_SYNC_EVENT_FLAGS_H_
102 STK_STATIC_ASSERT_DESC(
static_cast<T
>(-1) >
static_cast<T
>(0),
"EventFlagsT: T must be an unsigned integer type");
115 static constexpr T
FLAGS_MAX =
static_cast<T
>(~static_cast<T>(0U));
236 T
Get()
const {
return ReadFlags(ReadTag<(
sizeof(T) >
sizeof(
void *))>()); }
369 return m_cv.GetWaitList();
382 return m_cv.GetFirstWaiterTid();
418#if (__cplusplus < 201703L)
450 if ((flags != 0U) && ((flags &
ERROR_MASK) == 0U))
473 if ((flags != 0U) && ((flags &
ERROR_MASK) == 0U))
505 Timeout timeout_ticks, T &actual_flags)
514 const Timeout deadline = (timed_wait ?
526 remaining = (now >= deadline ?
NO_WAIT : (deadline - now));
552 flags :
static_cast<T
>(
m_flags & flags));
566 if ((flags == 0U) || ((flags &
ERROR_MASK) != 0U))
584 flags :
static_cast<T
>(actual & flags));
605 Timeout timeout_ticks, T &actual_flags)
609 if ((flags == 0U) || ((flags &
ERROR_MASK) != 0U) ||
613 actual_flags =
Get();
617 result =
WaitCore(flags, options, timeout_ticks, actual_flags);
629 Timeout timeout_ticks, T &actual_flags)
633 if ((wait_flags == 0U) || ((wait_flags &
ERROR_MASK) != 0U) || ((set_flags &
ERROR_MASK) != 0U) ||
637 actual_flags =
Get();
644 const Timeout deadline = (timed_wait ?
652 const uint32_t gen = ctx.
m_gen;
656 if (ctx.
m_gen != gen)
683 remaining = (now >= deadline ?
NO_WAIT : (deadline - now));
692 if (ctx.
m_gen != gen)
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_NONCOPYABLE_CLASS(TYPE)
Deletes (= delete) the copy constructor and copy assignment operator of a class.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define STK_STATIC_ASSERT_DESC(X, DESC)
Compile-time assertion with a custom error description. Produces a compilation error if X is false.
#define STK_VIRT_DTOR
Expands to nothing if STK_STRICT_COMPLIANCY=0 (non-virtual destructors, smaller objects),...
Implementation of synchronization primitive: stk::sync::ConditionVariable.
Namespace of STK package.
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
EWaitResult
Wait result (see IKernelService::Wait).
@ WAIT_RESULT_FAIL
IKernelService::Wait returned with error without waiting.
@ WAIT_RESULT_CANCELED
The wait was cancelled by another task via IKernel::CancelTaskWait(), independent of signal/timeout.
@ WAIT_RESULT_SIGNAL
The wake was caused by a signal.
int32_t Timeout
Timeout time (ticks).
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Word TId
Task (thread) id.
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
Synchronization primitives for task coordination and resource protection.
EventFlagsT< uint32_t > EventFlags
Default event flags group with a 32-bit flags word (31 usable flags, bit 31 reserved).
RAII instance that enters the critical section on construction and exits it on destruction.
DLHeadType ListHeadType
List head type for IWaitObject elements.
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.
Event flags group for multi-flag synchronization between tasks, with a selectable flags word type.
T And(T mask)
AND the flags word with a mask (equivalent of ThreadX tx_event_flags_set(TX_AND)).
T Set(T flags)
Set one or more flags.
static constexpr uint32_t OPT_WAIT_ANY
EWaitResult WaitEx(T flags, uint32_t options, Timeout timeout_ticks, T &actual_flags)
Wait for one or more flags to be set, reporting the outcome via EWaitResult.
const IWaitObject::ListHeadType & GetWaitList() const
Get list of tasks blocked on this object.
~EventFlagsT()=default
Destructor.
static constexpr uint32_t ERROR_MASK
static constexpr uint32_t OPT_NO_CLEAR
T Clear(T flags)
Clear one or more flags.
static constexpr uint32_t ERROR_CANCELED
T Wait(T flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout_ticks=WAIT_INFINITE)
Wait for one or more flags to be set.
EWaitResult WaitCore(T flags, uint32_t options, Timeout timeout_ticks, T &actual_flags)
T Get() const
Read the current flags word without modifying it.
EventFlagsT(T initial_flags=0U)
Constructor.
T TryWait(T flags, uint32_t options=OPT_WAIT_ANY)
Non-blocking flag poll.
EWaitResult TryWaitEx(T flags, uint32_t options, T &actual_flags)
Non-blocking flag poll with EWaitResult and full flags snapshot.
static constexpr uint32_t FLAGS_MASK
EWaitResult Sync(SyncContext &ctx, T set_flags, T wait_flags, Timeout timeout_ticks, T &actual_flags)
Atomically set flags and wait for a group of flags: a multi-task rendezvous (equivalent of FreeRTOS x...
static constexpr uint32_t OPT_WAIT_ALL
static constexpr uint32_t ERROR_ISR
static constexpr uint32_t ERROR_FAIL
T ReadFlags(ReadTag< true >) const
Flags word is wider than the native word: a plain load may be split into several, guard it.
static bool IsError(T result)
Checks if a return value from Set(), Clear(), or Wait() is an error.
static constexpr uint32_t ERROR_TIMEOUT
T ReadFlags(ReadTag< false >) const
Flags word fits the native word: a single load is atomic.
static constexpr uint32_t ERROR_PARAMETER
volatile uint32_t m_flags
TId GetFirstWaiterTid() const
Get id of the task which is first in the wait list (FIFO order), i.e. the one that WakeOne() would wa...
static constexpr uint32_t FLAGS_MAX
T FlagsValueType
Flags value type.
bool IsSatisfied(T flags, uint32_t options) const
State of one Sync() rendezvous group, supplied by the caller.
T m_snapshot
flags word captured when the last rendezvous completed
uint32_t m_gen
rendezvous generation, incremented when the rendezvous completes
Selects how the flags word is read: WIDE is true if T is wider than a pointer.