![]() |
SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Condition Variable primitive for signaling between tasks based on specific predicates. More...
#include <stk_sync_cv.h>
Public Member Functions | |
| ConditionVariable () | |
| ~ConditionVariable () | |
| Destructor. | |
| bool | Wait (IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE) |
| Wait for a signal. | |
| void | NotifyOne () |
| Wake one waiting task. | |
| void | NotifyOne_CS () |
| Wake one waiting task. | |
| void | NotifyAll () |
| Wake all waiting tasks. | |
| void | NotifyAll_CS () |
| Wake all waiting tasks. | |
| 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 | |
| ConditionVariable (const ConditionVariable &)=delete | |
| ConditionVariable & | operator= (const ConditionVariable &)=delete |
| virtual void | AddWaitObject (IWaitObject *wobj) |
| Called by kernel when a new task starts waiting on this event. | |
| virtual void | RemoveWaitObject (IWaitObject *wobj) |
| Called by kernel when a waiting task is being removed (timeout expired, wait aborted, task terminated etc.). | |
| 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. | |
| DLHeadType * | GetHead () |
| Get the list head this entry currently belongs to. | |
| DLEntryType * | GetNext () |
| Get the next entry in the list. | |
| DLEntryType * | GetPrev () |
| 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 | |
| IWaitObject::ListHeadType | m_wait_list |
| tasks blocked on this object | |
| DLHeadType * | m_head |
Owning list head, or NULL when the entry is not linked. | |
| 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). | |
Condition Variable primitive for signaling between tasks based on specific predicates.
Condition Variables are synchronization primitives that enable tasks to wait until a particular condition (predicate) is met. They must be used in conjunction with an IMutex-compatible lock to protect the shared state.
Wait() operation atomically releases the associated lock and suspends the task. Upon waking (via signal or timeout), the lock is automatically re-acquired before the function returns.Definition at line 67 of file stk_sync_cv.h.
|
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.
|
inherited |
Convenience alias for the corresponding list head type.
Definition at line 80 of file stk_linked_list.h.
|
inherited |
List entry type of ISyncObject elements.
Definition at line 451 of file stk_common.h.
|
inherited |
List head type for ISyncObject elements.
Definition at line 446 of file stk_common.h.
|
inherited |
A tag for type-safe casts done by CastListEntryToParent.
Definition at line 70 of file stk_linked_list.h.
|
inlineexplicit |
Definition at line 70 of file stk_sync_cv.h.
Referenced by ConditionVariable().
|
inline |
Destructor.
Definition at line 78 of file stk_sync_cv.h.
References stk::ISyncObject::m_wait_list, STK_ASSERT, and STK_VIRT_DTOR.
|
privatedelete |
|
inlinevirtualinherited |
Called by kernel when a new task starts waiting on this event.
| [in] | wobj | Wait object representing blocked task. |
Definition at line 457 of file stk_common.h.
References stk::util::DListEntry< T, TClosedLoop >::GetHead(), m_wait_list, and STK_ASSERT.
Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::SetupWait().
Find higher weight within linked wait objects.
Implementation of ISyncObject::Tick, see ISyncObject. Placed here as it depends on GetUserTaskFromTid.
| [in] | comp | Weight to compare with. |
Definition at line 214 of file stk_helper.h.
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().
|
inlineinherited |
Get the list head this entry currently belongs to.
NULL if the entry is not linked. Definition at line 85 of file stk_linked_list.h.
|
inlineinherited |
Get the next entry in the list.
NULL if this is the last entry (open list) or the first entry (closed loop, where next wraps to first). TClosedLoop == true) this pointer is never NULL when the entry is linked. Definition at line 98 of file stk_linked_list.h.
|
inlineinherited |
Get the previous entry in the list.
NULL if this is the first entry (open list) or the last entry (closed loop, where prev wraps to last). TClosedLoop == true) this pointer is never NULL when the entry is linked. Definition at line 114 of file stk_linked_list.h.
|
inlineinherited |
Get name.
NULL if not set or if STK_SYNC_DEBUG_NAMES is 0. Definition at line 416 of file stk_common.h.
|
inlineinherited |
Check whether this entry is currently a member of any list.
true if linked (m_head != NULL); false otherwise. Definition at line 127 of file stk_linked_list.h.
|
inlineprivateinherited |
Wire this entry into a list between prev and next.
| [in] | head | The owning DListHead. Stored as a back-pointer for IsLinked() and ownership checks. |
| [in] | next | The entry that will follow this one, or NULL if this becomes the last entry. |
| [in] | prev | The entry that will precede this one, or NULL if this becomes the first entry. |
Definition at line 162 of file stk_linked_list.h.
|
inline |
Wake all waiting tasks.
Definition at line 166 of file stk_sync_cv.h.
References NotifyAll_CS().
Referenced by stk_cv_notify_all().
|
inline |
Wake all waiting tasks.
Definition at line 176 of file stk_sync_cv.h.
References stk::ISyncObject::WakeAll().
Referenced by NotifyAll().
|
inline |
Wake one waiting task.
Definition at line 147 of file stk_sync_cv.h.
References NotifyOne_CS().
Referenced by stk_cv_notify_one().
|
inline |
Wake one waiting task.
Definition at line 157 of file stk_sync_cv.h.
References stk::ISyncObject::WakeOne().
Referenced by NotifyOne().
|
inlineinherited |
Implicit conversion to a const pointer to the host object (T).
Definition at line 141 of file stk_linked_list.h.
|
inlineinherited |
Implicit conversion to a mutable pointer to the host object (T).
Definition at line 134 of file stk_linked_list.h.
|
privatedelete |
|
inlinevirtualinherited |
Called by kernel when a waiting task is being removed (timeout expired, wait aborted, task terminated etc.).
| [in] | wobj | Wait object to remove from the wait list. |
Reimplemented in stk::sync::Event.
Definition at line 467 of file stk_common.h.
References stk::util::DListEntry< T, TClosedLoop >::GetHead(), m_wait_list, and STK_ASSERT.
Referenced by stk::sync::Event::RemoveWaitObject().
|
inlineinherited |
Set name.
| [in] | name | Null-terminated string or NULL. |
Definition at line 404 of file stk_common.h.
References STK_UNUSED.
Referenced by stk::memory::BlockMemoryPool::BlockMemoryPool(), and stk::memory::BlockMemoryPool::BlockMemoryPool().
|
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.
| [in] | elapsed_ticks | Number 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. |
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. 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(). Definition at line 181 of file stk_helper.h.
References stk::util::DListEntry< T, TClosedLoop >::GetNext(), stk::util::DListCast::ListEntryToParent(), m_wait_list, stk::IWaitObject::Tick(), and stk::IWaitObject::Wake().
|
inlineprivateinherited |
Remove this entry from its current list.
Definition at line 186 of file stk_linked_list.h.
|
inline |
Wait for a signal.
Atomically releases mutex and blocks the calling task. The mutex is re-acquired before the function returns, regardless of whether the wake was caused by a signal or a timeout.
| [in] | mutex | An IMutex-compatible lock that must be held by the calling task before Wait() is called. The kernel releases it atomically during suspension and re-acquires it on wake. |
| [in] | timeout_ticks | Maximum time to wait (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT to return immediately without blocking. |
true if signaled, false if timeout occurred or NO_WAIT was passed. Definition at line 127 of file stk_sync_cv.h.
References stk::IKernelService::GetInstance(), stk::hw::IsInsideISR(), stk::IWaitObject::IsTimeout(), stk::NO_WAIT, STK_ASSERT, and stk::IKernelService::Wait().
Referenced by osThreadJoin(), and stk_cv_wait().
|
inlineprotectedinherited |
Wake all tasks currently in the wait list.
Definition at line 526 of file stk_common.h.
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().
|
inlineprotectedinherited |
Wake the first task in the wait list (FIFO order).
Definition at line 512 of file stk_common.h.
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().
|
privateinherited |
Owning list head, or NULL when the entry is not linked.
Definition at line 203 of file stk_linked_list.h.
|
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.
|
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.
|
protectedinherited |
tasks blocked on this object
Definition at line 534 of file stk_common.h.
Referenced by AddWaitObject(), FindWeightHigherThan(), ISyncObject(), stk::sync::Event::Pulse(), RemoveWaitObject(), stk::sync::Semaphore::Signal(), Tick(), stk::sync::Mutex::Unlock(), WakeAll(), WakeOne(), stk::sync::ConditionVariable::~ConditionVariable(), stk::sync::Event::~Event(), stk::sync::Mutex::~Mutex(), and stk::sync::Semaphore::~Semaphore().