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::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject Class Referencefinal

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, TClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< IWaitObject, TClosedLoop > DLHeadType
 Convenience alias for the corresponding list head type.

Public Member Functions

 WaitObject ()
 ~WaitObject ()=default
 Destructor.
TId GetTid () const override
 Get the TId of the task that owns this wait object.
bool IsTimeout () const override
 Check whether the wait expired due to timeout.
bool IsWaiting () const
 Check if busy with waiting.
void Wake (bool timeout) override
 Wake the waiting task (called by ISyncObject when it signals).
bool Tick (Timeout elapsed_ticks) override
 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 ()
 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 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 402 of file stk.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<IWaitObject, TClosedLoop> stk::util::DListEntry< IWaitObject, TClosedLoop >::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, TClosedLoop> stk::util::DListEntry< IWaitObject, TClosedLoop >::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 345 of file stk_common.h.

◆ ListHeadType

List head type for IWaitObject elements.

Definition at line 340 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 404 of file stk.h.

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

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 ( )
default

Destructor.

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

References STK_VIRT_DTOR.

Member Function Documentation

◆ GetHead()

DLHeadType * stk::util::DListEntry< IWaitObject, 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 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, 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 93 of file stk_linked_list.h.

93{ return m_next; }

◆ GetPrev()

DLEntryType * stk::util::DListEntry< IWaitObject, 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 109 of file stk_linked_list.h.

109{ 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
inlineoverridevirtual

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

Returns
TId of m_task.

Implements stk::IWaitObject.

Definition at line 425 of file stk.h.

425{ return m_task->GetTid(); }

References m_task.

◆ IsLinked()

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

122{ 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
inlineoverridevirtual

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 430 of file stk.h.

430{ 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 435 of file stk.h.

435{ 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, 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 157 of file stk_linked_list.h.

158 {
159 m_head = head;
160 m_next = next;
161 m_prev = prev;
162
163 if (m_prev != nullptr)
164 {
165 m_prev->m_next = this;
166 }
167
168 if (m_next != nullptr)
169 {
170 m_next->m_prev = this;
171 }
172 }
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, TClosedLoop >::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, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 136 of file stk_linked_list.h.

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

◆ operator IWaitObject *()

stk::util::DListEntry< IWaitObject, TClosedLoop >::operator IWaitObject* ( )
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 129 of file stk_linked_list.h.

129{ 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 486 of file stk.h.

487 {
489
492 m_timeout = false;
493
494 sync_obj->AddWaitObject(this);
495 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:411
Concrete implementation of IKernel.
Definition stk.h:85
bool IsWaiting() const
Check if busy with waiting.
Definition stk.h:435

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)
inlineoverridevirtual

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 461 of file stk.h.

462 {
464 {
465 if (!m_timeout)
466 {
468
469 if (m_time_wait <= 0)
470 {
471 m_timeout = true;
472 }
473 }
474 }
475
476 return !m_timeout;
477 }

References m_time_wait, m_timeout, and stk::WAIT_INFINITE.

◆ Unlink()

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

182 {
183 if (m_prev != nullptr)
184 {
186 }
187
188 if (m_next != nullptr)
189 {
191 }
192
193 m_head = nullptr;
194 m_next = nullptr;
195 m_prev = nullptr;
196 }

◆ Wake()

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

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 442 of file stk.h.

443 {
445
447 m_time_wait = 0;
448
449 m_sync_obj->RemoveWaitObject(this);
450 m_sync_obj = nullptr;
451
452 return m_task->Wake();
453 }

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, TClosedLoop >::m_head
privateinherited

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

Definition at line 198 of file stk_linked_list.h.

◆ m_next

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

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

Definition at line 199 of file stk_linked_list.h.

◆ m_prev

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

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

Definition at line 200 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 498 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 497 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 500 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 499 of file stk.h.

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


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