SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject Class Reference

Concrete implementation of IWaitObject, embedded in each KernelTask slot. More...

#include <stk.h>

Inheritance diagram for stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject:
Collaboration diagram for stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject:

Classes

class  WaitRequest
 Payload stored in the sync object's kernel-side list entry while a task is waiting. More...

Public Types

typedef DLHeadType ListHeadType
 List head type for IWaitObject elements.
typedef DLEntryType ListEntryType
 List entry type of IWaitObject elements.
typedef DListEntry< IWaitObject, _ClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< IWaitObject, _ClosedLoop > DLHeadType
 Convenience alias for the corresponding list head type.

Public Member Functions

 WaitObject ()
 ~WaitObject ()
 Destructor.
TId GetTid () const
 Get the TId of the task that owns this wait object.
bool IsTimeout () const
 Check whether the wait expired due to timeout.
bool IsWaiting () const
 Check if busy with waiting.
void Wake (bool timeout)
 Wake the waiting task (called by ISyncObject when it signals).
bool Tick (Timeout elapsed_ticks)
 Advance the timeout countdown by one tick.
void SetupWait (ISyncObject *sync_obj, Timeout timeout)
 Configure and arm this wait object for a new wait operation.
DLHeadTypeGetHead () const
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext () const
 Get the next entry in the list.
DLEntryTypeGetPrev () const
 Get the previous entry in the list.
bool IsLinked () const
 Check whether this entry is currently a member of any list.
 operator IWaitObject * ()
 Implicit conversion to a mutable pointer to the host object (T).
 operator const IWaitObject * () const
 Implicit conversion to a const pointer to the host object (T).

Public Attributes

KernelTaskm_task
 Back-pointer to the owning KernelTask. Set once at construction; never changes.
ISyncObjectm_sync_obj
 Sync object this wait is registered with, or NULL when not waiting.
volatile bool m_timeout
 true if the wait expired due to timeout rather than a Wake() signal.
Timeout m_time_wait
 Ticks remaining until timeout. Decremented each tick; WAIT_INFINITE means no timeout.

Private Member Functions

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

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

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
class stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject

Concrete implementation of IWaitObject, embedded in each KernelTask slot.

Note
Allocated only when TMode includes KERNEL_SYNC. Zero-size otherwise.
One WaitObject per KernelTask, the back-pointer m_task is wired at KernelTask construction and never changes.

Definition at line 344 of file stk.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<IWaitObject, _ClosedLoop> stk::util::DListEntry< IWaitObject, _ClosedLoop >::DLEntryType
inherited

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

Definition at line 70 of file stk_linked_list.h.

◆ DLHeadType

typedef DListHead<IWaitObject, _ClosedLoop> stk::util::DListEntry< IWaitObject, _ClosedLoop >::DLHeadType
inherited

Convenience alias for the corresponding list head type.

Definition at line 75 of file stk_linked_list.h.

◆ ListEntryType

List entry type of IWaitObject elements.

Definition at line 280 of file stk_common.h.

◆ ListHeadType

List head type for IWaitObject elements.

Definition at line 275 of file stk_common.h.

Constructor & Destructor Documentation

◆ WaitObject()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::WaitObject ( )
inlineexplicit

Definition at line 346 of file stk.h.

346 : m_task(nullptr), m_sync_obj(nullptr), m_timeout(false), m_time_wait(0)
347 {}
Timeout m_time_wait
Ticks remaining until timeout. Decremented each tick; WAIT_INFINITE means no timeout.
Definition stk.h:438
volatile bool m_timeout
true if the wait expired due to timeout rather than a Wake() signal.
Definition stk.h:437
ISyncObject * m_sync_obj
Sync object this wait is registered with, or NULL when not waiting.
Definition stk.h:436
KernelTask * m_task
Back-pointer to the owning KernelTask. Set once at construction; never changes.
Definition stk.h:435

References m_sync_obj, m_task, m_time_wait, and m_timeout.

◆ ~WaitObject()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::~WaitObject ( )
inline

Destructor.

Note
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

Definition at line 352 of file stk.h.

353 {}

Member Function Documentation

◆ GetHead()

DLHeadType * stk::util::DListEntry< IWaitObject, _ClosedLoop >::GetHead ( ) const
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 80 of file stk_linked_list.h.

80{ return m_head; }
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

◆ GetNext()

DLEntryType * stk::util::DListEntry< IWaitObject, _ClosedLoop >::GetNext ( ) const
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 (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 88 of file stk_linked_list.h.

88{ return m_next; }

◆ GetPrev()

DLEntryType * stk::util::DListEntry< IWaitObject, _ClosedLoop >::GetPrev ( ) const
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 (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 96 of file stk_linked_list.h.

96{ return m_prev; }

◆ GetTid()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
TId stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::GetTid ( ) const
inlinevirtual

Get the TId of the task that owns this wait object.

Returns
TId of m_task.

Implements stk::IWaitObject.

Definition at line 368 of file stk.h.

368{ return m_task->GetTid(); }

References m_task.

◆ IsLinked()

bool stk::util::DListEntry< IWaitObject, _ClosedLoop >::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 101 of file stk_linked_list.h.

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

◆ IsTimeout()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::IsTimeout ( ) const
inlinevirtual

Check whether the wait expired due to timeout.

Returns
true if the wait timed out before being signalled, false if woken by Wake().

Implements stk::IWaitObject.

Definition at line 373 of file stk.h.

373{ return m_timeout; }

References m_timeout.

◆ IsWaiting()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::IsWaiting ( ) const
inline

Check if busy with waiting.

Returns
true if waiting, false if not.

Definition at line 378 of file stk.h.

378{ return (m_sync_obj != nullptr); }

References m_sync_obj.

Referenced by SetupWait(), and Wake().

Here is the caller graph for this function:

◆ Link()

void stk::util::DListEntry< IWaitObject, _ClosedLoop >::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 137 of file stk_linked_list.h.

138 {
139 m_head = head;
140 m_next = next;
141 m_prev = prev;
142
143 if (m_prev != nullptr)
144 m_prev->m_next = this;
145
146 if (m_next != nullptr)
147 m_next->m_prev = this;
148 }
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 IWaitObject *()

stk::util::DListEntry< IWaitObject, _ClosedLoop >::operator const IWaitObject * ( ) const
inlineinherited

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

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

Definition at line 115 of file stk_linked_list.h.

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

◆ operator IWaitObject *()

stk::util::DListEntry< IWaitObject, _ClosedLoop >::operator IWaitObject* ( )
inlineinherited

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

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

Definition at line 108 of file stk_linked_list.h.

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

◆ SetupWait()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::SetupWait ( ISyncObject * sync_obj,
Timeout timeout )
inline

Configure and arm this wait object for a new wait operation.

Parameters
[in]sync_objThe synchronization object to wait on. Must not already have this wait object registered (asserted).
[in]timeoutMaximum ticks to wait, or WAIT_INFINITE for no timeout.
Note
Registers this object with sync_obj's wait list via AddWaitObject(). Must be paired with a matching Wake() or timeout expiry.

Definition at line 424 of file stk.h.

425 {
427
430 m_timeout = false;
431
432 sync_obj->AddWaitObject(this);
433 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
Concrete implementation of IKernel.
Definition stk.h:81
bool IsWaiting() const
Check if busy with waiting.
Definition stk.h:378

References stk::ISyncObject::AddWaitObject(), IsWaiting(), m_sync_obj, m_time_wait, m_timeout, and STK_ASSERT.

Here is the call graph for this function:

◆ Tick()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::Tick ( Timeout elapsed_ticks)
inlinevirtual

Advance the timeout countdown by one tick.

Returns
true if the wait is still active (not yet timed out), false if the timeout just expired (caller should stop ticking this object).
Note
Called by UpdateSyncObjects() each kernel tick. WAIT_INFINITE waits never time out and always return true.

Implements stk::IWaitObject.

Definition at line 404 of file stk.h.

405 {
407 {
409
410 if (m_time_wait <= 0)
411 m_timeout = true;
412 }
413
414 return !m_timeout;
415 }

References m_time_wait, m_timeout, and stk::WAIT_INFINITE.

◆ Unlink()

void stk::util::DListEntry< IWaitObject, _ClosedLoop >::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 157 of file stk_linked_list.h.

158 {
159 if (m_prev != nullptr)
161
162 if (m_next != nullptr)
164
165 m_head = nullptr;
166 m_next = nullptr;
167 m_prev = nullptr;
168 }

◆ Wake()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::Wake ( bool timeout)
inlinevirtual

Wake the waiting task (called by ISyncObject when it signals).

Parameters
[in]timeouttrue if woken because the timeout expired, false if signalled.
Note
Clears m_time_wait, records the timeout flag, removes this object from m_sync_obj's wait list, nulls m_sync_obj, then calls m_task->Wake().

Implements stk::IWaitObject.

Definition at line 385 of file stk.h.

386 {
388
390 m_time_wait = 0;
391
392 m_sync_obj->RemoveWaitObject(this);
393 m_sync_obj = nullptr;
394
395 return m_task->Wake();
396 }

References IsWaiting(), m_sync_obj, m_task, m_time_wait, m_timeout, and STK_ASSERT.

Here is the call graph for this function:

Member Data Documentation

◆ m_head

DLHeadType* stk::util::DListEntry< IWaitObject, _ClosedLoop >::m_head
privateinherited

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

Definition at line 170 of file stk_linked_list.h.

◆ m_next

DLEntryType* stk::util::DListEntry< IWaitObject, _ClosedLoop >::m_next
privateinherited

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

Definition at line 171 of file stk_linked_list.h.

◆ m_prev

DLEntryType* stk::util::DListEntry< IWaitObject, _ClosedLoop >::m_prev
privateinherited

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

Definition at line 172 of file stk_linked_list.h.

◆ m_sync_obj

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
ISyncObject* stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::m_sync_obj

Sync object this wait is registered with, or NULL when not waiting.

Definition at line 436 of file stk.h.

Referenced by IsWaiting(), SetupWait(), WaitObject(), and Wake().

◆ m_task

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
KernelTask* stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::m_task

Back-pointer to the owning KernelTask. Set once at construction; never changes.

Definition at line 435 of file stk.h.

Referenced by GetTid(), WaitObject(), and Wake().

◆ m_time_wait

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::m_time_wait

Ticks remaining until timeout. Decremented each tick; WAIT_INFINITE means no timeout.

Definition at line 438 of file stk.h.

Referenced by SetupWait(), Tick(), WaitObject(), and Wake().

◆ m_timeout

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
volatile bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::m_timeout

true if the wait expired due to timeout rather than a Wake() signal.

Definition at line 437 of file stk.h.

Referenced by IsTimeout(), SetupWait(), Tick(), WaitObject(), and Wake().


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