![]() |
SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
32-bit event flags group for multi-flag synchronization between tasks. More...
#include <stk_sync_eventflags.h>
Public Member Functions | |
| EventFlags (uint32_t initial_flags=0U) | |
| Constructor. | |
| ~EventFlags () | |
| Destructor. | |
| uint32_t | Set (uint32_t flags) |
| Set one or more flags. | |
| uint32_t | Clear (uint32_t flags) |
| Clear one or more flags. | |
| uint32_t | Get () const |
| Read the current flags word without modifying it. | |
| 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 | TryWait (uint32_t flags, uint32_t options=OPT_WAIT_ANY) |
| Non-blocking flag poll. | |
| void | SetTraceName (const char *name) |
| Set name. | |
| const char * | GetTraceName () const |
| Get name. | |
Static Public Member Functions | |
| static bool | IsError (uint32_t result) |
| Checks if a return value from Set(), Clear(), or Wait() is an error. | |
Static Public Attributes | |
| static const uint32_t | OPT_WAIT_ANY = 0x00000000U |
| Wait for ANY of the specified flags to be set (OR semantics, default). | |
| static const uint32_t | OPT_WAIT_ALL = 0x00000001U |
| Wait for ALL of the specified flags to be set simultaneously (AND semantics). | |
| static const uint32_t | OPT_NO_CLEAR = 0x00000002U |
| Do not clear matched flags after a successful wait. | |
| static const uint32_t | ERROR_PARAMETER = 0x80000001U |
| Return sentinel: invalid flags argument (bit 31 set). | |
| static const uint32_t | ERROR_TIMEOUT = 0x80000002U |
| Return sentinel: wait timed out before the flags condition was met. | |
| static const uint32_t | ERROR_ISR = 0x80000004U |
| Return sentinel: called from an ISR with a blocking timeout. | |
| static const uint32_t | ERROR_MASK = 0x80000000U |
| Reserved error mask. Any return value with bit 31 set is an error. | |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (EventFlags) | |
| bool | IsSatisfied (uint32_t flags, uint32_t options) const |
Private Attributes | |
| volatile uint32_t | m_flags |
| 32-bit flags word (bit 31 is reserved for errors) | |
| ConditionVariable | m_cv |
| woken by Set() to re-evaluate waiting tasks | |
32-bit event flags group for multi-flag synchronization between tasks.
EventFlags maintains a 32-bit word where each bit represents an independent boolean event. Tasks can set or clear any combination of flags, and wait for any subset to become set — either requiring all requested flags (AND semantics) or any one of them (OR semantics).
Unlike Event, which models a single binary signal, EventFlags allows fine-grained coordination across up to 32 independent conditions in a single object.
WAIT_ANY (default) or WAIT_ALL. Wait(). Pass NO_CLEAR to suppress this. Set() notifies all waiters so that every task re-evaluates its own predicate after waking. Each waiter clears only the flags it matched, so concurrent waiters with disjoint flag masks do not interfere with each other. Definition at line 75 of file stk_sync_eventflags.h.
|
inlineexplicit |
Constructor.
| [in] | initial_flags | Initial value of the 32-bit flags word. Only bits 0..30 are meaningful; bit 31 is reserved. |
Definition at line 125 of file stk_sync_eventflags.h.
References ERROR_MASK, m_flags, and STK_ASSERT.
Referenced by STK_NONCOPYABLE_CLASS().
|
inline |
Destructor.
Definition at line 135 of file stk_sync_eventflags.h.
|
inline |
Clear one or more flags.
Atomically clears the specified flags from the internal word.
| [in] | flags | Bitmask of flags to clear. Must not have bit 31 set. |
ERROR_PARAMETER if flags is 0 or has bit 31 set. Definition at line 255 of file stk_sync_eventflags.h.
References ERROR_MASK, ERROR_PARAMETER, and m_flags.
Referenced by stk_ef_clear().
|
inline |
Read the current flags word without modifying it.
Definition at line 272 of file stk_sync_eventflags.h.
References m_flags.
Referenced by stk_ef_get().
|
inlineinherited |
Get name.
NULL if not set or if STK_SYNC_DEBUG_NAMES is 0. Definition at line 278 of file stk_common.h.
|
inlinestatic |
Checks if a return value from Set(), Clear(), or Wait() is an error.
true when the value carries an error sentinel (bit 31 set). Definition at line 115 of file stk_sync_eventflags.h.
References ERROR_MASK.
Referenced by stk::test::eventflags::ClearTask< _AccessMode >::Run(), stk::test::eventflags::GetTask< _AccessMode >::Run(), stk::test::eventflags::InitialFlagsTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAllTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAnyTask< _AccessMode >::Run(), stk::test::eventflags::NoClearTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAllTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAnyTask< _AccessMode >::Run(), stk::test::eventflags::TimeoutTask< _AccessMode >::Run(), and stk::test::eventflags::TryWaitTask< _AccessMode >::Run().
|
inlineprivate |
Definition at line 219 of file stk_sync_eventflags.h.
References m_flags, and OPT_WAIT_ALL.
Referenced by Wait().
|
inline |
Set one or more flags.
Performs an atomic OR of flags into the internal flags word, then wakes all tasks currently waiting on this object so that each can re-evaluate its own wait condition.
| [in] | flags | Bitmask of flags to set. Must not have bit 31 set. |
ERROR_PARAMETER if flags is 0 or has bit 31 set. Definition at line 235 of file stk_sync_eventflags.h.
References ERROR_MASK, ERROR_PARAMETER, m_cv, and m_flags.
Referenced by stk_ef_set().
|
inlineinherited |
Set name.
| [in] | name | Null-terminated string or NULL. |
Definition at line 266 of file stk_common.h.
|
private |
|
inline |
Non-blocking flag poll.
Checks immediately whether the flag condition is satisfied. Clears matched flags on success unless NO_CLEAR is set.
| [in] | flags | Bitmask of flag bits to watch. |
| [in] | options | WAIT_ANY (default) or WAIT_ALL, optionally NO_CLEAR. |
ERROR_* sentinel. Definition at line 209 of file stk_sync_eventflags.h.
References stk::NO_WAIT, OPT_WAIT_ANY, and Wait().
Referenced by stk_ef_trywait().
|
inline |
Wait for one or more flags to be set.
Suspends the calling task until the requested flag condition is satisfied or the timeout expires.
On success the matched flags are atomically cleared (unless NO_CLEAR is passed in options).
| [in] | flags | Bitmask of flag bits to watch. Must not be 0 and must not have bit 31 set. |
| [in] | options | Combination of WAIT_ANY / WAIT_ALL and optionally NO_CLEAR. Default: WAIT_ANY (clear on success). |
| [in] | timeout | Maximum time to wait (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking poll. |
ERROR_* sentinels on failure. Always check IsError() before using the return value as a flags mask. NO_WAIT, ISR-unsafe otherwise. Definition at line 283 of file stk_sync_eventflags.h.
References ERROR_ISR, ERROR_MASK, ERROR_PARAMETER, ERROR_TIMEOUT, stk::GetTicks(), stk::hw::IsInsideISR(), IsSatisfied(), m_cv, m_flags, stk::NO_WAIT, OPT_NO_CLEAR, OPT_WAIT_ALL, and stk::WAIT_INFINITE.
Referenced by stk_ef_wait(), and TryWait().
|
static |
Return sentinel: called from an ISR with a blocking timeout.
Definition at line 103 of file stk_sync_eventflags.h.
Referenced by Wait().
|
static |
Reserved error mask. Any return value with bit 31 set is an error.
Definition at line 106 of file stk_sync_eventflags.h.
Referenced by Clear(), EventFlags(), IsError(), Set(), and Wait().
|
static |
Return sentinel: invalid flags argument (bit 31 set).
Definition at line 97 of file stk_sync_eventflags.h.
|
static |
Return sentinel: wait timed out before the flags condition was met.
Definition at line 100 of file stk_sync_eventflags.h.
Referenced by stk::test::eventflags::InitialFlagsTask< _AccessMode >::Run(), stk::test::eventflags::TimeoutTask< _AccessMode >::Run(), and Wait().
|
private |
woken by Set() to re-evaluate waiting tasks
Definition at line 228 of file stk_sync_eventflags.h.
|
private |
32-bit flags word (bit 31 is reserved for errors)
Definition at line 227 of file stk_sync_eventflags.h.
Referenced by Clear(), EventFlags(), Get(), IsSatisfied(), Set(), and Wait().
|
static |
Do not clear matched flags after a successful wait.
Definition at line 90 of file stk_sync_eventflags.h.
Referenced by stk::test::eventflags::NoClearTask< _AccessMode >::Run(), and Wait().
|
static |
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
Definition at line 87 of file stk_sync_eventflags.h.
Referenced by IsSatisfied(), stk::test::eventflags::MultiWaiterAllTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAllTask< _AccessMode >::Run(), and Wait().
|
static |
Wait for ANY of the specified flags to be set (OR semantics, default).
Definition at line 84 of file stk_sync_eventflags.h.
Referenced by stk::test::eventflags::ClearTask< _AccessMode >::Run(), stk::test::eventflags::GetTask< _AccessMode >::Run(), stk::test::eventflags::InitialFlagsTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAnyTask< _AccessMode >::Run(), stk::test::eventflags::NoClearTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAnyTask< _AccessMode >::Run(), stk::test::eventflags::TimeoutTask< _AccessMode >::Run(), and TryWait().