SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::sync::Event Class Referencefinal

Binary synchronization event (signaled / non-signaled) primitive. More...

#include <stk_sync_event.h>

Inheritance diagram for stk::sync::Event:
Collaboration diagram for stk::sync::Event:

Public Member Functions

 Event (bool manual_reset=false, bool initial_state=false)
 Constructor.
 ~Event ()
 Destructor.
bool Set ()
 Set event to signaled state.
bool Reset ()
 Reset event to non-signaled state.
bool Wait (Timeout timeout_ticks=WAIT_INFINITE)
 Wait until event becomes signaled or the timeout expires.
bool TryWait ()
 Poll event state without blocking.
void Pulse ()
 Pulse event: attempt to release waiters and then reset (Win32 PulseEvent() semantics).
void SetTraceName (const char *name)
 Set name.
const char * GetTraceName () const
 Get name.

Private Types

typedef DLHeadType ListHeadType
 List head type for ISyncObject elements.
typedef DLEntryType ListEntryType
 List entry type of ISyncObject elements.
enum  
 A tag for type-safe casts done by CastListEntryToParent. More...
typedef DListEntry< ISyncObject, TClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< ISyncObject, TClosedLoop > DLHeadType
 Convenience alias for the corresponding list head type.

Private Member Functions

 Event (const Event &)=delete
Eventoperator= (const Event &)=delete
void RemoveWaitObject (IWaitObject *wobj) override
 Called by kernel when a waiting task is being removed (timeout expired, wait aborted, task terminated etc.).
virtual void AddWaitObject (IWaitObject *wobj)
 Called by kernel when a new task starts waiting on this event.
virtual bool Tick (Timeout elapsed_ticks)
 Called by kernel on every system tick to handle timeout logic of waiting tasks.
Weight FindWeightHigherThan (Weight comp) const
 Find higher weight within linked wait objects.
void WakeOne ()
 Wake the first task in the wait list (FIFO order).
void WakeAll ()
 Wake all tasks currently in the wait list.
DLHeadTypeGetHead ()
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext ()
 Get the next entry in the list.
DLEntryTypeGetPrev ()
 Get the previous entry in the list.
bool IsLinked () const
 Check whether this entry is currently a member of any list.
 operator ISyncObject * ()
 Implicit conversion to a mutable pointer to the host object (T).
 operator const ISyncObject * () const
 Implicit conversion to a const pointer to the host object (T).
void Link (DLHeadType *head, DLEntryType *next, DLEntryType *prev)
 Wire this entry into a list between prev and next.
void Unlink ()
 Remove this entry from its current list.

Private Attributes

bool m_manual_reset
 true = manual-reset event, false = auto-reset
bool m_signaled
 current signaled state of the event
IWaitObject::ListHeadType m_wait_list
 tasks blocked on this object
DLHeadTypem_head
 Owning list head, or NULL when the entry is not linked.
DLEntryTypem_next
 Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryTypem_prev
 Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Detailed Description

Binary synchronization event (signaled / non-signaled) primitive.

Supports two operation modes:

  • Auto-reset (default): Set() wakes one waiting task and automatically resets.
  • Manual-reset: Set() wakes all waiting tasks; state remains signaled until Reset().

Additionally, supports Pulse(): attempt to release waiters and then reset (Win32 PulseEvent() semantics).

Note
Follows Win32 PulseEvent() behavior:
  • For auto-reset events: releases one waiting thread (if any) and resets to non-signaled.
  • For manual-reset events: releases all waiting threads (if any) and resets to non-signaled.
  • If no threads are waiting, resets to non-signaled.
Warning
Pulse semantics are inherently racy and considered unreliable in many Win32 usage scenarios. Prefer explicit Set() + Reset() patterns when possible.
// Example: Task synchronization using Event
stk::sync::Event g_DataReadyEvt;
void Task_Producer() {
// ... produce data ...
// notify Task_Consumer that data is ready
g_DataReadyEvt.Set();
}
void Task_Consumer() {
// wait for a data-ready notification signal from Task_Producer with 1s timeout
if (g_DataReadyEvt.Wait(1000)) {
// ... process data ...
}
}
Binary synchronization event (signaled / non-signaled) primitive.
bool Set()
Set event to signaled state.
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait until event becomes signaled or the timeout expires.
See also
ISyncObject, IWaitObject, IKernelService::Wait
Note
Only available when kernel is compiled with KERNEL_SYNC mode enabled.

Definition at line 61 of file stk_sync_event.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<ISyncObject, TClosedLoop> stk::util::DListEntry< ISyncObject, TClosedLoop >::DLEntryType
inherited

Convenience alias for this entry type. Used to avoid repeating the full template spelling.

Definition at line 75 of file stk_linked_list.h.

◆ DLHeadType

typedef DListHead<ISyncObject, TClosedLoop> stk::util::DListEntry< ISyncObject, TClosedLoop >::DLHeadType
inherited

Convenience alias for the corresponding list head type.

Definition at line 80 of file stk_linked_list.h.

◆ ListEntryType

List entry type of ISyncObject elements.

Definition at line 451 of file stk_common.h.

◆ ListHeadType

List head type for ISyncObject elements.

Definition at line 446 of file stk_common.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited

A tag for type-safe casts done by CastListEntryToParent.

See also
CastListEntryToParent.

Definition at line 70 of file stk_linked_list.h.

70{ DLEntryTag = 1 };
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

Constructor & Destructor Documentation

◆ Event() [1/2]

stk::sync::Event::Event ( bool manual_reset = false,
bool initial_state = false )
inlineexplicit

Constructor.

Parameters
[in]manual_resetIf true creates a manual-reset event (stays signaled until explicitly reset). If false (default) creates an auto-reset event.
[in]initial_stateInitial state of the event: true = signaled, false = non-signaled.

Definition at line 69 of file stk_sync_event.h.

70 : m_manual_reset(manual_reset), m_signaled(initial_state)
71 {}
bool m_signaled
current signaled state of the event
bool m_manual_reset
true = manual-reset event, false = auto-reset

References m_manual_reset, and m_signaled.

Referenced by Event().

Here is the caller graph for this function:

◆ ~Event()

stk::sync::Event::~Event ( )
inline

Destructor.

Note
If tasks are still waiting at destruction time it is considered a logical error (dangling waiters). An assertion is triggered in debug builds.
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

Definition at line 78 of file stk_sync_event.h.

79 {
80 STK_ASSERT(m_wait_list.IsEmpty()); // API contract: must not be destroyed with waiting tasks
81 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
IWaitObject::ListHeadType m_wait_list
tasks blocked on this object
Definition stk_common.h:534

References stk::ISyncObject::m_wait_list, STK_ASSERT, and STK_VIRT_DTOR.

◆ Event() [2/2]

stk::sync::Event::Event ( const Event & )
privatedelete

References Event().

Here is the call graph for this function:

Member Function Documentation

◆ AddWaitObject()

virtual void stk::ISyncObject::AddWaitObject ( IWaitObject * wobj)
inlinevirtualinherited

Called by kernel when a new task starts waiting on this event.

Parameters
[in]wobjWait object representing blocked task.
Note
Must be called inside the critical section (see hw::CriticalSection, sync::ScopedCrticalSection).

Definition at line 457 of file stk_common.h.

458 {
459 STK_ASSERT(wobj->GetHead() == nullptr);
460 m_wait_list.LinkBack(wobj);
461 }

References stk::util::DListEntry< T, TClosedLoop >::GetHead(), m_wait_list, and STK_ASSERT.

Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::SetupWait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindWeightHigherThan()

Weight stk::ISyncObject::FindWeightHigherThan ( Weight comp) const
inlineinherited

Find higher weight within linked wait objects.

Implementation of ISyncObject::Tick, see ISyncObject. Placed here as it depends on GetUserTaskFromTid.

Parameters
[in]compWeight to compare with.
Returns
Higher weight value than comp, or NO_WEIGHT if there is no object with a higher weight.
Note
Must be called inside the critical section (see hw::CriticalSection, sync::ScopedCrticalSection).

Definition at line 214 of file stk_helper.h.

215{
216 Weight max_weight = NO_WEIGHT;
217 const IWaitObject *itr = util::DListCast::ListEntryToParent<const IWaitObject>(m_wait_list.GetFirst());
218
219 while (itr != nullptr)
220 {
221 const Weight w = GetUserTaskFromTid(itr->GetTid())->GetWeight();
222 if (w > max_weight)
223 {
224 max_weight = w;
225 }
226
228 }
229
230 return ((max_weight > comp) ? max_weight : NO_WEIGHT);
231}
static constexpr ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
Definition stk_arch.h:526
constexpr Weight NO_WEIGHT
Weight value: weight is not set.
Definition stk_common.h:194
int32_t Weight
Weight value (aka priority).
Definition stk_common.h:145
virtual Weight GetWeight() const
Get static base weight of the task.
Definition stk_common.h:645
static __stk_forceinline TTargetType * ListEntryToParent(TSourceType *const lentry)
Safely casts an intrusive list entry to its concrete parent container object type.

References stk::util::DListEntry< T, TClosedLoop >::GetNext(), stk::IWaitObject::GetTid(), stk::GetUserTaskFromTid(), stk::ITask::GetWeight(), stk::util::DListCast::ListEntryToParent(), m_wait_list, and stk::NO_WEIGHT.

Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >::OnRestoreWeight(), and stk::sync::Mutex::Unlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHead()

DLHeadType * stk::util::DListEntry< ISyncObject, TClosedLoop >::GetHead ( )
inlineinherited

Get the list head this entry currently belongs to.

Returns
Pointer to the owning DListHead, or NULL if the entry is not linked.

Definition at line 85 of file stk_linked_list.h.

85{ return m_head; }

◆ GetNext()

DLEntryType * stk::util::DListEntry< ISyncObject, TClosedLoop >::GetNext ( )
inlineinherited

Get the next entry in the list.

Returns
Pointer to the next DListEntry, or NULL if this is the last entry (open list) or the first entry (closed loop, where next wraps to first).
Note
In a closed loop (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 98 of file stk_linked_list.h.

98{ return m_next; }

◆ GetPrev()

DLEntryType * stk::util::DListEntry< ISyncObject, TClosedLoop >::GetPrev ( )
inlineinherited

Get the previous entry in the list.

Returns
Pointer to the previous DListEntry, or NULL if this is the first entry (open list) or the last entry (closed loop, where prev wraps to last).
Note
In a closed loop (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 114 of file stk_linked_list.h.

114{ return m_prev; }

◆ GetTraceName()

const char * stk::ITraceable::GetTraceName ( ) const
inlineinherited

Get name.

Returns
Name string, or NULL if not set or if STK_SYNC_DEBUG_NAMES is 0.

Definition at line 416 of file stk_common.h.

417 {
418 #if STK_SYNC_DEBUG_NAMES
419 return m_trace_name;
420 #else
421 return nullptr;
422 #endif
423 }

◆ IsLinked()

bool stk::util::DListEntry< ISyncObject, TClosedLoop >::IsLinked ( ) const
inlineinherited

Check whether this entry is currently a member of any list.

Returns
true if linked (m_head != NULL); false otherwise.

Definition at line 127 of file stk_linked_list.h.

127{ return (GetHead() != nullptr); }

◆ Link()

void stk::util::DListEntry< ISyncObject, TClosedLoop >::Link ( DLHeadType * head,
DLEntryType * next,
DLEntryType * prev )
inlineprivateinherited

Wire this entry into a list between prev and next.

Parameters
[in]headThe owning DListHead. Stored as a back-pointer for IsLinked() and ownership checks.
[in]nextThe entry that will follow this one, or NULL if this becomes the last entry.
[in]prevThe entry that will precede this one, or NULL if this becomes the first entry.
Note
Called exclusively by DListHead::Link(). Assumes the entry is not currently linked. Updates the neighbours' forward/back pointers to splice this entry in.

Definition at line 162 of file stk_linked_list.h.

163 {
164 m_head = head;
165 m_next = next;
166 m_prev = prev;
167
168 if (m_prev != nullptr)
169 {
170 m_prev->m_next = this;
171 }
172
173 if (m_next != nullptr)
174 {
175 m_next->m_prev = this;
176 }
177 }
DLEntryType * m_next
Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryType * m_prev
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

◆ operator const ISyncObject *()

stk::util::DListEntry< ISyncObject, TClosedLoop >::operator const ISyncObject * ( ) const
inlineinherited

Implicit conversion to a const pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 141 of file stk_linked_list.h.

141{ return static_cast<const T *>(this); }

◆ operator ISyncObject *()

stk::util::DListEntry< ISyncObject, TClosedLoop >::operator ISyncObject* ( )
inlineinherited

Implicit conversion to a mutable pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 134 of file stk_linked_list.h.

134{ return static_cast<T *>(this); }

◆ operator=()

Event & stk::sync::Event::operator= ( const Event & )
privatedelete

◆ Pulse()

void stk::sync::Event::Pulse ( )
inline

Pulse event: attempt to release waiters and then reset (Win32 PulseEvent() semantics).

Note
Follows Win32 PulseEvent() behavior:
  • For auto-reset events: releases one waiting thread (if any) and resets to non-signaled.
  • For manual-reset events: releases all waiting threads (if any) and resets to non-signaled.
  • If no threads are waiting, resets to non-signaled.
ISR-safe.
Warning
Pulse semantics are inherently racy and considered unreliable in many Win32 usage scenarios. Prefer explicit Set() + Reset() patterns when possible.

Definition at line 194 of file stk_sync_event.h.

195{
196 const ScopedCriticalSection cs_;
197
198 // transition to signaled so that WakeOne/WakeAll can release waiters:
199 // m_signaled is only visible as true while this critical section is held —
200 // any woken task will have the event auto-reset in RemoveWaitObject before
201 // it can observe m_signaled via Wait() or TryWait()
202 m_signaled = true;
203 __stk_full_memfence();
204
205 if (!m_wait_list.IsEmpty())
206 {
207 if (m_manual_reset)
208 {
209 WakeAll();
210 }
211 else
212 {
213 WakeOne(); // auto-reset applied in RemoveWaitObject
214 }
215 }
216
217 // force return to non-signaled regardless of whether anyone was waiting
218 m_signaled = false;
219 __stk_full_memfence();
220}
void WakeOne()
Wake the first task in the wait list (FIFO order).
Definition stk_common.h:512
void WakeAll()
Wake all tasks currently in the wait list.
Definition stk_common.h:526

References m_manual_reset, m_signaled, stk::ISyncObject::m_wait_list, stk::ISyncObject::WakeAll(), and stk::ISyncObject::WakeOne().

Referenced by stk_event_pulse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveWaitObject()

void stk::sync::Event::RemoveWaitObject ( IWaitObject * wobj)
inlineoverrideprivatevirtual

Called by kernel when a waiting task is being removed (timeout expired, wait aborted, task terminated etc.).

Parameters
[in]wobjWait object to remove from the wait list.
Note
Must be called inside the critical section (see hw::CriticalSection, sync::ScopedCrticalSection).

Reimplemented from stk::ISyncObject.

Definition at line 285 of file stk_sync_event.h.

286{
288
289 // kernel invariant: auto-reset is applied here, not at the Set()/Pulse() call site,
290 // when a task wakes due to a signal (not a timeout), the event transitions back to
291 // non-signaled so that subsequent Wait() calls block until the next Set().
293 {
294 if (!wobj->IsTimeout())
295 {
296 m_signaled = false;
297 __stk_full_memfence();
298 }
299 }
300}
virtual void RemoveWaitObject(IWaitObject *wobj)
Called by kernel when a waiting task is being removed (timeout expired, wait aborted,...
Definition stk_common.h:467

References stk::IWaitObject::IsTimeout(), m_manual_reset, m_signaled, and stk::ISyncObject::RemoveWaitObject().

Here is the call graph for this function:

◆ Reset()

bool stk::sync::Event::Reset ( )
inline

Reset event to non-signaled state.

Returns
true if state was changed from signaled to non-signaled, false if event was already non-signaled.
Note
Has no practical effect on auto-reset events that are already non-signaled. Mainly used with manual-reset events.
ISR-safe.

Definition at line 178 of file stk_sync_event.h.

179{
180 const ScopedCriticalSection cs_;
181
182 const bool prev = m_signaled;
183
184 m_signaled = false;
185 __stk_full_memfence();
186
187 return prev;
188}

References m_signaled.

Referenced by stk_event_reset().

Here is the caller graph for this function:

◆ Set()

bool stk::sync::Event::Set ( )
inline

Set event to signaled state.

Returns
true if state was changed from non-signaled to signaled, false if event was already signaled.
Note
- In auto-reset mode: wakes one waiting task (if any) and immediately resets.
  • In manual-reset mode: wakes all waiting tasks (if any); state remains set.
  • If already signaled, does nothing and returns false.
Warning
The return value indicates whether the event state changed, not whether any waiting task was woken. A return of false means the event was already signaled, not that no task woke.
Note
ISR-safe.

Definition at line 147 of file stk_sync_event.h.

148{
149 const ScopedCriticalSection cs_;
150 bool status = true;
151
152 if (m_signaled)
153 {
154 status = false;
155 }
156 else
157 {
158 m_signaled = true;
159 __stk_full_memfence();
160
161 if (m_manual_reset)
162 {
163 WakeAll();
164 }
165 else
166 {
167 WakeOne(); // auto-reset is applied in RemoveWaitObject when the waiter is removed
168 }
169 }
170
171 return status;
172}

References m_manual_reset, m_signaled, stk::ISyncObject::WakeAll(), and stk::ISyncObject::WakeOne().

Referenced by stk_event_set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetTraceName()

void stk::ITraceable::SetTraceName ( const char * name)
inlineinherited

Set name.

Parameters
[in]nameNull-terminated string or NULL.
Note
If STK_SYNC_DEBUG_NAMES is 0 then calling this function has no effect.

Definition at line 404 of file stk_common.h.

405 {
406 #if STK_SYNC_DEBUG_NAMES
407 m_trace_name = name;
408 #else
409 STK_UNUSED(name);
410 #endif
411 }
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:608

References STK_UNUSED.

Referenced by stk::memory::BlockMemoryPool::BlockMemoryPool(), and stk::memory::BlockMemoryPool::BlockMemoryPool().

Here is the caller graph for this function:

◆ Tick()

bool stk::ISyncObject::Tick ( Timeout elapsed_ticks)
inlinevirtualinherited

Called by kernel on every system tick to handle timeout logic of waiting tasks.

Implementation of ISyncObject::Tick, see ISyncObject. Placed here as it depends on hw namespace.

Parameters
[in]elapsed_ticksNumber of ticks elapsed between this and previous calls, in case of KERNEL_TICKLESS mode this value can be >1, for non-tickless mode it is always 1.
Returns
true if this synchronization object still has waiters with a finite timeout and requires further tick calls. false if the wait list is empty or all remaining waiters have infinite timeouts, signaling to the kernel that it may stop calling Tick() for this object until a new waiter is added.
Note
When this method returns false, the kernel unlinks this object from its active sync list. It will be re-linked automatically when the next waiter is added via AddWaitObject().
Does not need to be called inside critical section.

Definition at line 181 of file stk_helper.h.

182{
183 // note: ScopedCriticalSection usage
184 //
185 // Single-core: no critical section needed - Tick() runs inside the
186 // SysTick ISR which already executes with interrupts disabled, making
187 // re-entrancy impossible on the local core.
188 //
189 // Multi-core: critical section is required because the tick handler on
190 // each core may call Tick() concurrently for the same Semaphore instance,
191 // and ISyncObject::Tick() is not re-entrant.
192#if (STK_ARCH_CPU_COUNT > 1)
193 hw::CriticalSection::ScopedLock cs_;
194#endif
195
197
198 while (itr != nullptr)
199 {
200 IWaitObject *const next = util::DListCast::ListEntryToParent<IWaitObject>(itr->GetNext());
201
202 if (!itr->Tick(elapsed_ticks))
203 {
204 itr->Wake(true);
205 }
206
207 itr = next;
208 }
209
210 return !m_wait_list.IsEmpty();
211}

References stk::util::DListEntry< T, TClosedLoop >::GetNext(), stk::util::DListCast::ListEntryToParent(), m_wait_list, stk::IWaitObject::Tick(), and stk::IWaitObject::Wake().

Here is the call graph for this function:

◆ TryWait()

bool stk::sync::Event::TryWait ( )
inline

Poll event state without blocking.

Checks if the event is currently signaled. If signaled, performs the auto-reset (if auto-reset mode is active) and returns immediately without yielding the CPU or entering a wait list.

Note
ISR-safe.
Returns
true if event was signaled at the time of the call, false if event was not signaled.

Definition at line 262 of file stk_sync_event.h.

263{
264 const ScopedCriticalSection cs_;
265 bool result = false;
266
267 if (m_signaled)
268 {
269 if (!m_manual_reset)
270 {
271 m_signaled = false;
272 __stk_full_memfence();
273 }
274
275 result = true;
276 }
277
278 return result;
279}

References m_manual_reset, and m_signaled.

Referenced by stk_event_trywait().

Here is the caller graph for this function:

◆ Unlink()

void stk::util::DListEntry< ISyncObject, TClosedLoop >::Unlink ( )
inlineprivateinherited

Remove this entry from its current list.

Note
Called exclusively by DListHead::Unlink(). Patches the neighbours' pointers to bridge over this entry, then clears m_head, m_next, and m_prev to NULL so the entry is in a clean unlinked state.
Does not update DListHead::m_count or m_first / m_last — those are the responsibility of the calling DListHead::Unlink().

Definition at line 186 of file stk_linked_list.h.

187 {
188 if (m_prev != nullptr)
189 {
191 }
192
193 if (m_next != nullptr)
194 {
196 }
197
198 m_head = nullptr;
199 m_next = nullptr;
200 m_prev = nullptr;
201 }

◆ Wait()

bool stk::sync::Event::Wait ( Timeout timeout_ticks = WAIT_INFINITE)
inline

Wait until event becomes signaled or the timeout expires.

Parameters
[in]timeout_ticksMaximum time to wait (ticks). Use WAIT_INFINITE for no timeout (wait forever).
Warning
ISR-safe only with timeout_ticks = NO_WAIT, ISR-unsafe otherwise.
Returns
true if event was signaled (wait succeeded), false if timeout occurred before the event was signaled.

Definition at line 226 of file stk_sync_event.h.

227{
228 STK_ASSERT(!hw::IsInsideISR()); // API contract: caller must not be in ISR
229
230 ScopedCriticalSection cs_;
231 bool success = false;
232
233 // fast path: already signaled
234 if (m_signaled)
235 {
236 if (!m_manual_reset)
237 {
238 m_signaled = false;
239 __stk_full_memfence();
240 }
241
242 success = true;
243 }
244 // slow path: block until Set() signals the event or timeout expires
245 else if (timeout_ticks != NO_WAIT)
246 {
247 success = !IKernelService::GetInstance()->Wait(this, &cs_, timeout_ticks)->IsTimeout();
248 }
249 else
250 {
251 // non-blocking poll: event not signaled, return immediately
252 // success is already false, so noop
253 }
254
255 return success;
256}
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:189
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
virtual bool IsTimeout() const =0
Check if task woke up due to a timeout.
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.

References stk::IKernelService::GetInstance(), stk::hw::IsInsideISR(), stk::IWaitObject::IsTimeout(), m_manual_reset, m_signaled, stk::NO_WAIT, STK_ASSERT, and stk::IKernelService::Wait().

Referenced by stk_event_wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WakeAll()

void stk::ISyncObject::WakeAll ( )
inlineprotectedinherited

Wake all tasks currently in the wait list.

Note
Each woken task is notified with timeout=false, indicating a successful signal (not a timeout expiry).
Does nothing if no tasks are currently waiting.
Must be called inside the critical section (see hw::CriticalSection, sync::ScopedCrticalSection).

Definition at line 526 of file stk_common.h.

527 {
528 while (IWaitObject *const obj = util::DListCast::ListEntryToParent<IWaitObject>(m_wait_list.GetFirst()))
529 {
530 obj->Wake(false);
531 }
532 }

References stk::util::DListCast::ListEntryToParent(), and m_wait_list.

Referenced by stk::sync::ConditionVariable::NotifyAll_CS(), stk::sync::Event::Pulse(), and stk::sync::Event::Set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WakeOne()

void stk::ISyncObject::WakeOne ( )
inlineprotectedinherited

Wake the first task in the wait list (FIFO order).

Note
The woken task is notified with timeout=false, indicating a successful signal (not a timeout expiry).
Does nothing if no tasks are currently waiting.
Must be called inside the critical section (see hw::CriticalSection, sync::ScopedCrticalSection).

Definition at line 512 of file stk_common.h.

513 {
514 if (IWaitObject *const obj = util::DListCast::ListEntryToParent<IWaitObject>(m_wait_list.GetFirst()))
515 {
516 obj->Wake(false);
517 }
518 }

References stk::util::DListCast::ListEntryToParent(), and m_wait_list.

Referenced by stk::sync::ConditionVariable::NotifyOne_CS(), stk::sync::Event::Pulse(), stk::sync::Event::Set(), and stk::sync::Semaphore::Signal().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_head

DLHeadType* stk::util::DListEntry< ISyncObject, TClosedLoop >::m_head
privateinherited

Owning list head, or NULL when the entry is not linked.

Definition at line 203 of file stk_linked_list.h.

◆ m_manual_reset

bool stk::sync::Event::m_manual_reset
private

true = manual-reset event, false = auto-reset

Definition at line 139 of file stk_sync_event.h.

Referenced by Event(), Pulse(), RemoveWaitObject(), Set(), TryWait(), and Wait().

◆ m_next

DLEntryType* stk::util::DListEntry< ISyncObject, TClosedLoop >::m_next
privateinherited

Next entry in the list, or NULL (open list boundary) / first entry (closed loop).

Definition at line 204 of file stk_linked_list.h.

◆ m_prev

DLEntryType* stk::util::DListEntry< ISyncObject, TClosedLoop >::m_prev
privateinherited

Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Definition at line 205 of file stk_linked_list.h.

◆ m_signaled

bool stk::sync::Event::m_signaled
private

current signaled state of the event

Definition at line 140 of file stk_sync_event.h.

Referenced by Event(), Pulse(), RemoveWaitObject(), Reset(), Set(), TryWait(), and Wait().

◆ m_wait_list


The documentation for this class was generated from the following file: