SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
anonymous_namespace{threadx_stk.cpp} Namespace Reference

Classes

class  StkThread
class  ScopedWaitKind
class  StkBytePool
class  StkTimerThread

Functions

__stk_forceinline bool InIsr ()
__stk_forceinline bool KernelRunning ()
__stk_forceinline bool KernelInitialized ()
__stk_forceinline stk::Timeout ToStkTimeout (ULONG wait_option)
__stk_forceinline stk::Weight ToStkWeight (UINT priority, UINT threshold)
__stk_forceinline UINT WaitResultToTx (stk::EWaitResult wr, UINT timeout_status)
__stk_forceinline StkThread * ThreadOf (TX_THREAD *tx)
__stk_forceinline bool IsValidThread (const TX_THREAD *tx)
StkThread * CurrentThread ()
TX_THREAD * ThreadFromTid (stk::TId tid)
static void FillSuspended (const stk::ISyncObject &sobj, TX_THREAD **first_suspended, ULONG *suspended_count)
static void FillSuspended (const stk::sync::EventFlags &wf, TX_THREAD **first_suspended, ULONG *suspended_count)
__stk_forceinline bool CanBlock (ULONG wait_option)
UINT ThreadStateOf (TX_THREAD *tx)
UINT RegisterThread (StkThread *th)
bool WaitThreadRemoved (const StkThread *th)
__stk_forceinline stk::sync::Mutex * MutexOf (TX_MUTEX *m)
__stk_forceinline bool IsValidMutex (const TX_MUTEX *m)
__stk_forceinline stk::sync::Semaphore * SemOf (TX_SEMAPHORE *s)
__stk_forceinline bool IsValidSem (const TX_SEMAPHORE *s)
__stk_forceinline stk::sync::EventFlags * EfOf (TX_EVENT_FLAGS_GROUP *g)
__stk_forceinline bool IsValidEf (const TX_EVENT_FLAGS_GROUP *g)
__stk_forceinline stk::sync::MessageQueue * QueueOf (TX_QUEUE *q)
__stk_forceinline bool IsValidQueue (const TX_QUEUE *q)
UINT QueueSend (TX_QUEUE *queue_ptr, void *source_ptr, ULONG wait_option, bool front)
__stk_forceinline stk::memory::BlockMemoryPool * BlockPoolOf (TX_BLOCK_POOL *p)
__stk_forceinline bool IsValidBlockPool (const TX_BLOCK_POOL *p)
__stk_forceinline StkBytePool * BytePoolOf (TX_BYTE_POOL *p)
__stk_forceinline bool IsValidBytePool (const TX_BYTE_POOL *p)
void BytePoolLink (StkBytePool *p)
void BytePoolUnlink (StkBytePool *p)
StkBytePool * BytePoolFind (const void *mem)
void TimerListRemove (TX_TIMER *t)
bool TimerListInsert (TX_TIMER *t)
UINT EnsureTimerThread ()
__stk_forceinline bool IsValidTimer (const TX_TIMER *t)

Variables

stk::TId g_TimerTid = stk::TID_NONE
volatile bool g_IntDisabled = false
int64_t g_TimeOffset = 0
const size_t BLOCK_HDR_SIZE = sizeof(void *)
StkBytePool * g_BytePools = nullptr
StkTimerThread g_TimerThread
stk::sync::Event g_TimerEvent (false, false)
TX_TIMER * g_TimerHead = nullptr

Function Documentation

◆ BlockPoolOf()

__stk_forceinline stk::memory::BlockMemoryPool * anonymous_namespace{threadx_stk.cpp}::BlockPoolOf ( TX_BLOCK_POOL * p)

Definition at line 1938 of file threadx_stk.cpp.

1939{
1940 return static_cast<stk::memory::BlockMemoryPool *>(static_cast<void *>(p->tx_block_pool_stk_storage));
1941}
Fixed-size block allocator with O(1) alloc/free and proper task-blocking semantics.
ALIGN_TYPE tx_block_pool_stk_storage[(32U)]
Definition tx_api.h:298

References __stk_forceinline, BlockPoolOf(), and TX_BLOCK_POOL_STRUCT::tx_block_pool_stk_storage.

Referenced by BlockPoolOf().

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

◆ BytePoolFind()

StkBytePool * anonymous_namespace{threadx_stk.cpp}::BytePoolFind ( const void * mem)

Definition at line 2217 of file threadx_stk.cpp.

2218{
2220
2221 while ((p != nullptr) && !p->Contains(mem))
2222 {
2223 p = p->m_next;
2224 }
2225
2226 return p;
2227}

References BytePoolFind(), anonymous_namespace{threadx_stk.cpp}::StkBytePool::Contains(), g_BytePools, and anonymous_namespace{threadx_stk.cpp}::StkBytePool::m_next.

Referenced by BytePoolFind().

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

◆ BytePoolLink()

void anonymous_namespace{threadx_stk.cpp}::BytePoolLink ( StkBytePool * p)

Definition at line 2192 of file threadx_stk.cpp.

2193{
2194 p->m_next = g_BytePools;
2195 g_BytePools = p;
2196}

References BytePoolLink(), g_BytePools, and anonymous_namespace{threadx_stk.cpp}::StkBytePool::m_next.

Referenced by BytePoolLink().

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

◆ BytePoolOf()

__stk_forceinline StkBytePool * anonymous_namespace{threadx_stk.cpp}::BytePoolOf ( TX_BYTE_POOL * p)

Definition at line 2182 of file threadx_stk.cpp.

2183{
2184 return static_cast<StkBytePool *>(static_cast<void *>(p->tx_byte_pool_stk_storage));
2185}
ALIGN_TYPE tx_byte_pool_stk_storage[(24U)]
Definition tx_api.h:305

References __stk_forceinline, BytePoolOf(), and TX_BYTE_POOL_STRUCT::tx_byte_pool_stk_storage.

Referenced by BytePoolOf().

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

◆ BytePoolUnlink()

void anonymous_namespace{threadx_stk.cpp}::BytePoolUnlink ( StkBytePool * p)

Definition at line 2199 of file threadx_stk.cpp.

2200{
2201 StkBytePool **link = &g_BytePools;
2202
2203 while ((*link != nullptr) && (*link != p))
2204 {
2205 link = &((*link)->m_next);
2206 }
2207
2208 if (*link != nullptr)
2209 {
2210 *link = p->m_next;
2211 }
2212
2213 p->m_next = nullptr;
2214}

References BytePoolUnlink(), g_BytePools, and anonymous_namespace{threadx_stk.cpp}::StkBytePool::m_next.

Referenced by BytePoolUnlink().

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

◆ CanBlock()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::CanBlock ( ULONG wait_option)

Definition at line 291 of file threadx_stk.cpp.

292{
293 return ((wait_option == TX_NO_WAIT) || (CurrentThread() != nullptr));
294}
#define TX_NO_WAIT
Definition tx_api.h:127

References __stk_forceinline, CanBlock(), CurrentThread(), and TX_NO_WAIT.

Referenced by CanBlock(), and QueueSend().

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

◆ CurrentThread()

StkThread * anonymous_namespace{threadx_stk.cpp}::CurrentThread ( )

Definition at line 224 of file threadx_stk.cpp.

225{
226 StkThread *th = nullptr;
227
228 if (!InIsr() && KernelRunning())
229 {
230 const stk::TId tid = stk::GetTid();
231
232 if ((tid != stk::TID_NONE) && (tid != g_TimerTid))
233 {
234 th = static_cast<StkThread *>(stk::GetUserTaskFromTid(tid));
235 }
236 }
237
238 return th;
239}
static constexpr ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
Definition stk_arch.h:725
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:376
static constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Definition stk_common.h:222
Word TId
Task (thread) id.
Definition stk_common.h:165
__stk_forceinline bool KernelRunning()
__stk_forceinline bool InIsr()

References CurrentThread(), g_TimerTid, stk::GetTid(), stk::GetUserTaskFromTid(), InIsr(), KernelRunning(), and stk::TID_NONE.

Referenced by CanBlock(), CurrentThread(), and anonymous_namespace{threadx_stk.cpp}::ScopedWaitKind::ScopedWaitKind().

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

◆ EfOf()

__stk_forceinline stk::sync::EventFlags * anonymous_namespace{threadx_stk.cpp}::EfOf ( TX_EVENT_FLAGS_GROUP * g)

Definition at line 1473 of file threadx_stk.cpp.

1474{
1475 return static_cast<stk::sync::EventFlags *>(static_cast<void *>(g->tx_event_flags_group_stk_storage));
1476}
32-bit event flags group for multi-flag synchronization between tasks.
ALIGN_TYPE tx_event_flags_group_stk_storage[(24U)]
Definition tx_api.h:282

References __stk_forceinline, EfOf(), and TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_stk_storage.

Referenced by EfOf().

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

◆ EnsureTimerThread()

UINT anonymous_namespace{threadx_stk.cpp}::EnsureTimerThread ( )

Definition at line 2592 of file threadx_stk.cpp.

2593{
2594 UINT result = TX_SUCCESS;
2595
2596 if (!g_TimerThread.m_started)
2597 {
2598 if (g_StkKernel.GetSwitchStrategy()->GetSize() >= static_cast<size_t>(TX_STK_MAX_THREADS + 1U))
2599 {
2600 result = TX_NO_MEMORY;
2601 }
2602 else
2603 {
2604 g_TimerThread.m_started = true;
2606
2607 g_StkKernel.AddTask(&g_TimerThread);
2608 }
2609 }
2610
2611 return result;
2612}
static StkKernel g_StkKernel
unsigned int UINT
Definition tx_api.h:108
#define TX_SUCCESS
Definition tx_api.h:177
#define TX_STK_MAX_THREADS
Definition tx_api.h:54
#define TX_NO_MEMORY
Definition tx_api.h:193
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:716

References EnsureTimerThread(), g_StkKernel, g_TimerThread, g_TimerTid, stk::GetTidFromUserTask(), TX_NO_MEMORY, TX_STK_MAX_THREADS, and TX_SUCCESS.

Referenced by EnsureTimerThread().

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

◆ FillSuspended() [1/2]

void anonymous_namespace{threadx_stk.cpp}::FillSuspended ( const stk::ISyncObject & sobj,
TX_THREAD ** first_suspended,
ULONG * suspended_count )
static

Definition at line 256 of file threadx_stk.cpp.

257{
258 size_t count = 0U;
259 stk::TId first = stk::TID_NONE;
260
261 {
263
264 count = sobj.GetWaitList().GetSize();
265 first = sobj.GetFirstWaiterTid();
266 }
267
268 if (suspended_count != nullptr) { *suspended_count = static_cast<ULONG>(count); }
269 if (first_suspended != nullptr) { *first_suspended = ThreadFromTid(first); } // TID_NONE -> nullptr
270}
unsigned int ULONG
Definition tx_api.h:114
TX_THREAD * ThreadFromTid(stk::TId tid)
TId GetFirstWaiterTid() const
Get id of the task which is first in the wait list (FIFO order), i.e. the one that WakeOne() would wa...
Definition stk_common.h:726
virtual const IWaitObject::ListHeadType & GetWaitList() const =0
Get list of tasks blocked on this object.
size_t GetSize() const
Get the number of entries currently in the list.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:54

References FillSuspended(), stk::ISyncObject::GetFirstWaiterTid(), stk::util::DListHead< T, TClosedLoop >::GetSize(), stk::ISyncObject::GetWaitList(), ThreadFromTid(), and stk::TID_NONE.

Referenced by FillSuspended(), and FillSuspended().

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

◆ FillSuspended() [2/2]

void anonymous_namespace{threadx_stk.cpp}::FillSuspended ( const stk::sync::EventFlags & wf,
TX_THREAD ** first_suspended,
ULONG * suspended_count )
static

Definition at line 274 of file threadx_stk.cpp.

275{
276 size_t count = 0U;
277 stk::TId first = stk::TID_NONE;
278
279 {
281
282 count = wf.GetWaitList().GetSize();
283 first = wf.GetFirstWaiterTid();
284 }
285
286 if (suspended_count != nullptr) { *suspended_count = static_cast<ULONG>(count); }
287 if (first_suspended != nullptr) { *first_suspended = ThreadFromTid(first); } // TID_NONE -> nullptr
288}
const IWaitObject::ListHeadType & GetWaitList() const
Get list of tasks blocked on this object.
TId GetFirstWaiterTid() const
Get id of the task which is first in the wait list (FIFO order), i.e. the one that WakeOne() would wa...

References FillSuspended(), stk::sync::EventFlags::GetFirstWaiterTid(), stk::util::DListHead< T, TClosedLoop >::GetSize(), stk::sync::EventFlags::GetWaitList(), ThreadFromTid(), and stk::TID_NONE.

Here is the call graph for this function:

◆ InIsr()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::InIsr ( )

Definition at line 63 of file threadx_stk.cpp.

64{
65 return stk::hw::IsInsideISR();
66}
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).

References __stk_forceinline, InIsr(), and stk::hw::IsInsideISR().

Referenced by CurrentThread(), InIsr(), and WaitThreadRemoved().

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

◆ IsValidBlockPool()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidBlockPool ( const TX_BLOCK_POOL * p)

Definition at line 1942 of file threadx_stk.cpp.

1943{
1944 return ((p != nullptr) && (p->tx_block_pool_id == TX_BLOCK_POOL_ID));
1945}
#define TX_BLOCK_POOL_ID
Definition tx_api.h:221

References __stk_forceinline, IsValidBlockPool(), TX_BLOCK_POOL_ID, and TX_BLOCK_POOL_STRUCT::tx_block_pool_id.

Referenced by IsValidBlockPool().

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

◆ IsValidBytePool()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidBytePool ( const TX_BYTE_POOL * p)

Definition at line 2186 of file threadx_stk.cpp.

2187{
2188 return ((p != nullptr) && (p->tx_byte_pool_id == TX_BYTE_POOL_ID));
2189}
#define TX_BYTE_POOL_ID
Definition tx_api.h:222
ULONG tx_byte_pool_id
Definition tx_api.h:303

References __stk_forceinline, IsValidBytePool(), TX_BYTE_POOL_ID, and TX_BYTE_POOL_STRUCT::tx_byte_pool_id.

Referenced by IsValidBytePool().

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

◆ IsValidEf()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidEf ( const TX_EVENT_FLAGS_GROUP * g)

Definition at line 1477 of file threadx_stk.cpp.

1478{
1479 return ((g != nullptr) && (g->tx_event_flags_group_id == TX_EVENT_FLAGS_ID));
1480}
#define TX_EVENT_FLAGS_ID
Definition tx_api.h:220

References __stk_forceinline, IsValidEf(), TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_id, and TX_EVENT_FLAGS_ID.

Referenced by IsValidEf().

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

◆ IsValidMutex()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidMutex ( const TX_MUTEX * m)

Definition at line 1110 of file threadx_stk.cpp.

1110{ return ((m != nullptr) && (m->tx_mutex_id == TX_MUTEX_ID)); }
#define TX_MUTEX_ID
Definition tx_api.h:217
ULONG tx_mutex_id
Definition tx_api.h:264

References __stk_forceinline, IsValidMutex(), TX_MUTEX_ID, and TX_MUTEX_STRUCT::tx_mutex_id.

Referenced by IsValidMutex().

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

◆ IsValidQueue()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidQueue ( const TX_QUEUE * q)

Definition at line 1705 of file threadx_stk.cpp.

1705{ return ((q != nullptr) && (q->tx_queue_id == TX_QUEUE_ID)); }
#define TX_QUEUE_ID
Definition tx_api.h:218
ULONG tx_queue_id
Definition tx_api.h:287

References __stk_forceinline, IsValidQueue(), TX_QUEUE_ID, and TX_QUEUE_STRUCT::tx_queue_id.

Referenced by IsValidQueue(), and QueueSend().

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

◆ IsValidSem()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidSem ( const TX_SEMAPHORE * s)

Definition at line 1266 of file threadx_stk.cpp.

1266{ return ((s != nullptr) && (s->tx_semaphore_id == TX_SEMAPHORE_ID)); }
#define TX_SEMAPHORE_ID
Definition tx_api.h:219
ULONG tx_semaphore_id
Definition tx_api.h:271

References __stk_forceinline, IsValidSem(), TX_SEMAPHORE_ID, and TX_SEMAPHORE_STRUCT::tx_semaphore_id.

Referenced by IsValidSem().

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

◆ IsValidThread()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidThread ( const TX_THREAD * tx)

Definition at line 218 of file threadx_stk.cpp.

219{
220 return ((tx != nullptr) && (tx->tx_thread_id == TX_THREAD_ID));
221}
#define TX_THREAD_ID
Definition tx_api.h:216
ULONG tx_thread_id
Definition tx_api.h:243

References __stk_forceinline, IsValidThread(), TX_THREAD_ID, and TX_THREAD_STRUCT::tx_thread_id.

Referenced by IsValidThread().

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

◆ IsValidTimer()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::IsValidTimer ( const TX_TIMER * t)

Definition at line 2614 of file threadx_stk.cpp.

2614{ return ((t != nullptr) && (t->tx_timer_id == TX_TIMER_ID)); }
#define TX_TIMER_ID
Definition tx_api.h:223
ULONG tx_timer_id
Definition tx_api.h:311

References __stk_forceinline, IsValidTimer(), TX_TIMER_ID, and TX_TIMER_STRUCT::tx_timer_id.

Referenced by IsValidTimer().

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

◆ KernelInitialized()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::KernelInitialized ( )

Definition at line 73 of file threadx_stk.cpp.

74{
75 return (g_StkKernel.GetState() != stk::IKernel::KSTATE_INACTIVE);
76}
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.

References __stk_forceinline, g_StkKernel, KernelInitialized(), and stk::IKernel::KSTATE_INACTIVE.

Referenced by KernelInitialized().

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

◆ KernelRunning()

__stk_forceinline bool anonymous_namespace{threadx_stk.cpp}::KernelRunning ( )

Definition at line 68 of file threadx_stk.cpp.

69{
70 return (g_StkKernel.GetState() == stk::IKernel::KSTATE_RUNNING);
71}
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.

References __stk_forceinline, g_StkKernel, KernelRunning(), and stk::IKernel::KSTATE_RUNNING.

Referenced by CurrentThread(), KernelRunning(), and WaitThreadRemoved().

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

◆ MutexOf()

__stk_forceinline stk::sync::Mutex * anonymous_namespace{threadx_stk.cpp}::MutexOf ( TX_MUTEX * m)

Definition at line 1106 of file threadx_stk.cpp.

1107{
1108 return static_cast<stk::sync::Mutex *>(static_cast<void *>(m->tx_mutex_stk_storage));
1109}
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
ALIGN_TYPE tx_mutex_stk_storage[(16U)]
Definition tx_api.h:266

References __stk_forceinline, MutexOf(), and TX_MUTEX_STRUCT::tx_mutex_stk_storage.

Referenced by MutexOf().

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

◆ QueueOf()

__stk_forceinline stk::sync::MessageQueue * anonymous_namespace{threadx_stk.cpp}::QueueOf ( TX_QUEUE * q)

Definition at line 1701 of file threadx_stk.cpp.

1702{
1703 return static_cast<stk::sync::MessageQueue *>(static_cast<void *>(q->tx_queue_stk_storage));
1704}
Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.
ALIGN_TYPE tx_queue_stk_storage[(48U)]
Definition tx_api.h:291

References __stk_forceinline, QueueOf(), and TX_QUEUE_STRUCT::tx_queue_stk_storage.

Referenced by QueueOf(), and QueueSend().

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

◆ QueueSend()

UINT anonymous_namespace{threadx_stk.cpp}::QueueSend ( TX_QUEUE * queue_ptr,
void * source_ptr,
ULONG wait_option,
bool front )

Definition at line 1832 of file threadx_stk.cpp.

1833{
1834 UINT result;
1835
1836 if (!IsValidQueue(queue_ptr))
1837 {
1838 result = TX_QUEUE_ERROR;
1839 }
1840 else if (source_ptr == nullptr)
1841 {
1842 result = TX_PTR_ERROR;
1843 }
1844 else if (!CanBlock(wait_option))
1845 {
1846 result = TX_WAIT_ERROR;
1847 }
1848 else
1849 {
1850 stk::sync::MessageQueue *const q = QueueOf(queue_ptr);
1851 const stk::Timeout timeout = ToStkTimeout(wait_option);
1852
1853 {
1854 const ScopedWaitKind ws(TX_QUEUE_SUSP, wait_option);
1855
1856 result = WaitResultToTx((front ? q->PutFrontEx(source_ptr, timeout) : q->PutEx(source_ptr, timeout)),
1858 }
1859
1860 if ((result == TX_SUCCESS) && (queue_ptr->tx_queue_send_notify != nullptr))
1861 {
1862 queue_ptr->tx_queue_send_notify(queue_ptr);
1863 }
1864 }
1865
1866 return result;
1867}
#define TX_QUEUE_FULL
Definition tx_api.h:188
#define TX_WAIT_ERROR
Definition tx_api.h:181
#define TX_PTR_ERROR
Definition tx_api.h:180
#define TX_QUEUE_ERROR
Definition tx_api.h:186
#define TX_QUEUE_SUSP
Definition tx_api.h:165
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:170
__stk_forceinline bool IsValidQueue(const TX_QUEUE *q)
__stk_forceinline stk::sync::MessageQueue * QueueOf(TX_QUEUE *q)
__stk_forceinline bool CanBlock(ULONG wait_option)
__stk_forceinline UINT WaitResultToTx(stk::EWaitResult wr, UINT timeout_status)
__stk_forceinline stk::Timeout ToStkTimeout(ULONG wait_option)
EWaitResult PutEx(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order), preserving the full wait outcome.
EWaitResult PutFrontEx(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order), preserving the full wait ou...
void(* tx_queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr)
Definition tx_api.h:290

References CanBlock(), IsValidQueue(), stk::sync::MessageQueue::PutEx(), stk::sync::MessageQueue::PutFrontEx(), QueueOf(), QueueSend(), ToStkTimeout(), TX_PTR_ERROR, TX_QUEUE_ERROR, TX_QUEUE_FULL, TX_QUEUE_STRUCT::tx_queue_send_notify, TX_QUEUE_SUSP, TX_SUCCESS, TX_WAIT_ERROR, VOID, and WaitResultToTx().

Referenced by QueueSend().

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

◆ RegisterThread()

UINT anonymous_namespace{threadx_stk.cpp}::RegisterThread ( StkThread * th)

Definition at line 383 of file threadx_stk.cpp.

384{
385 UINT result = TX_SUCCESS;
386
387 if (g_StkKernel.GetSwitchStrategy()->GetSize() >= static_cast<size_t>(TX_STK_MAX_THREADS + 1U))
388 {
389 result = TX_START_ERROR; // out of kernel task slots: increase TX_STK_MAX_THREADS
390 }
391 else
392 {
393 th->m_removed = false;
394 th->m_registered = true;
396
397 g_StkKernel.AddTask(th);
398 }
399
400 return result;
401}
#define TX_READY
Definition tx_api.h:160
#define TX_START_ERROR
Definition tx_api.h:194
UINT tx_thread_state
Definition tx_api.h:250

References g_StkKernel, anonymous_namespace{threadx_stk.cpp}::StkThread::m_registered, anonymous_namespace{threadx_stk.cpp}::StkThread::m_removed, anonymous_namespace{threadx_stk.cpp}::StkThread::m_tx, RegisterThread(), TX_READY, TX_START_ERROR, TX_STK_MAX_THREADS, TX_SUCCESS, and TX_THREAD_STRUCT::tx_thread_state.

Referenced by RegisterThread().

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

◆ SemOf()

__stk_forceinline stk::sync::Semaphore * anonymous_namespace{threadx_stk.cpp}::SemOf ( TX_SEMAPHORE * s)

Definition at line 1262 of file threadx_stk.cpp.

1263{
1264 return static_cast<stk::sync::Semaphore *>(static_cast<void *>(s->tx_semaphore_stk_storage));
1265}
Counting semaphore primitive for resource management and signaling.
ALIGN_TYPE tx_semaphore_stk_storage[(16U)]
Definition tx_api.h:274

References __stk_forceinline, SemOf(), and TX_SEMAPHORE_STRUCT::tx_semaphore_stk_storage.

Referenced by SemOf().

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

◆ ThreadFromTid()

TX_THREAD * anonymous_namespace{threadx_stk.cpp}::ThreadFromTid ( stk::TId tid)

Definition at line 241 of file threadx_stk.cpp.

242{
243 TX_THREAD *tx = nullptr;
244
245 if ((tid != stk::TID_NONE) && (tid != g_TimerTid) && !stk::IsIsrTid(tid))
246 {
247 tx = static_cast<StkThread *>(stk::GetUserTaskFromTid(tid))->m_tx;
248 }
249
250 return tx;
251}
struct TX_THREAD_STRUCT TX_THREAD
static constexpr bool IsIsrTid(TId id)
Test whether a task identifier represents an ISR context.
Definition stk_common.h:263

References g_TimerTid, stk::GetUserTaskFromTid(), stk::IsIsrTid(), ThreadFromTid(), and stk::TID_NONE.

Referenced by FillSuspended(), FillSuspended(), and ThreadFromTid().

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

◆ ThreadOf()

__stk_forceinline StkThread * anonymous_namespace{threadx_stk.cpp}::ThreadOf ( TX_THREAD * tx)

Definition at line 213 of file threadx_stk.cpp.

214{
215 return static_cast<StkThread *>(static_cast<void *>(tx->tx_thread_stk_storage));
216}
ALIGN_TYPE tx_thread_stk_storage[(24U)]
Definition tx_api.h:259

References __stk_forceinline, ThreadOf(), and TX_THREAD_STRUCT::tx_thread_stk_storage.

Referenced by ThreadOf(), and ThreadStateOf().

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

◆ ThreadStateOf()

UINT anonymous_namespace{threadx_stk.cpp}::ThreadStateOf ( TX_THREAD * tx)

Definition at line 335 of file threadx_stk.cpp.

336{
337 UINT state = tx->tx_thread_state;
338
339 if (state == TX_READY)
340 {
341 StkThread *const th = ThreadOf(tx);
342
343 if (th->m_registered && !th->m_removed)
344 {
346
347 // fails only for a null task or without KERNEL_TELEMETRY: keep the lifecycle state then
348 if (!g_StkKernel.GetTaskState(th, info))
349 {
351 }
352
353 switch (info.state)
354 {
356 state = TX_SLEEP;
357 break;
358
360 state = ((th->m_wait_kind != TX_READY) ? th->m_wait_kind : static_cast<UINT>(TX_SLEEP));
361 break;
362
364 state = TX_SUSPENDED;
365 break;
366
368 state = TX_COMPLETED;
369 break;
370
373 default:
374 break; // TX_READY
375 }
376 }
377 }
378
379 return state;
380}
#define TX_SUSPENDED
Definition tx_api.h:163
#define TX_COMPLETED
Definition tx_api.h:161
#define TX_SLEEP
Definition tx_api.h:164
@ TASK_STATE_EXITING
Run() has returned, the slot is released on the next tick (KERNEL_DYNAMIC mode only).
Definition stk_common.h:87
@ TASK_STATE_SLEEPING
Sleeping via Sleep()/SleepUntil(), with a finite or an infinite timeout.
Definition stk_common.h:84
@ TASK_STATE_SUSPENDED
Suspended by IKernel::SuspendTask().
Definition stk_common.h:86
@ TASK_STATE_REMOVED
The task is not bound to a kernel slot (never added, or already removed).
Definition stk_common.h:82
@ TASK_STATE_WAITING
Blocked on a synchronization object (IKernelService::Wait). KERNEL_SYNC mode only.
Definition stk_common.h:85
@ TASK_STATE_READY
Runnable: running, or waiting for the CPU.
Definition stk_common.h:83
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:228
__stk_forceinline StkThread * ThreadOf(TX_THREAD *tx)
Snapshot of the kernel-side state of a task, filled in by IKernel::GetTaskState().
Definition stk_common.h:338
ETaskState state
Task state.
Definition stk_common.h:339

References g_StkKernel, anonymous_namespace{threadx_stk.cpp}::StkThread::m_registered, anonymous_namespace{threadx_stk.cpp}::StkThread::m_removed, anonymous_namespace{threadx_stk.cpp}::StkThread::m_wait_kind, stk::TaskStateInfo::state, stk::TASK_STATE_EXITING, stk::TASK_STATE_READY, stk::TASK_STATE_REMOVED, stk::TASK_STATE_SLEEPING, stk::TASK_STATE_SUSPENDED, stk::TASK_STATE_WAITING, ThreadOf(), ThreadStateOf(), TX_COMPLETED, TX_READY, TX_SLEEP, TX_SUSPENDED, TX_THREAD_STRUCT::tx_thread_state, and stk::WAIT_INFINITE.

Referenced by ThreadStateOf().

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

◆ TimerListInsert()

bool anonymous_namespace{threadx_stk.cpp}::TimerListInsert ( TX_TIMER * t)

Definition at line 2491 of file threadx_stk.cpp.

2492{
2493 TX_TIMER *prev = nullptr;
2494 TX_TIMER *next = g_TimerHead;
2495
2496 // stable: a timer is placed behind the timers expiring at the same tick
2497 while ((next != nullptr) && (next->tx_timer_stk_expiry <= t->tx_timer_stk_expiry))
2498 {
2499 prev = next;
2500 next = next->tx_timer_stk_next;
2501 }
2502
2503 t->tx_timer_stk_prev = prev;
2504 t->tx_timer_stk_next = next;
2505
2506 if (next != nullptr)
2507 {
2508 next->tx_timer_stk_prev = t;
2509 }
2510
2511 if (prev != nullptr)
2512 {
2513 prev->tx_timer_stk_next = t;
2514 }
2515 else
2516 {
2517 g_TimerHead = t;
2518 }
2519
2520 return (prev == nullptr);
2521}
struct TX_TIMER_STRUCT TX_TIMER
struct TX_TIMER_STRUCT * tx_timer_stk_next
Definition tx_api.h:319
uint64_t tx_timer_stk_expiry
Definition tx_api.h:318
struct TX_TIMER_STRUCT * tx_timer_stk_prev
Definition tx_api.h:320

References g_TimerHead, TimerListInsert(), TX_TIMER_STRUCT::tx_timer_stk_expiry, TX_TIMER_STRUCT::tx_timer_stk_next, and TX_TIMER_STRUCT::tx_timer_stk_prev.

Referenced by anonymous_namespace{threadx_stk.cpp}::StkTimerThread::Run(), and TimerListInsert().

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

◆ TimerListRemove()

void anonymous_namespace{threadx_stk.cpp}::TimerListRemove ( TX_TIMER * t)

Definition at line 2470 of file threadx_stk.cpp.

2471{
2472 if (t->tx_timer_stk_prev != nullptr)
2473 {
2475 }
2476 else
2477 {
2479 }
2480
2481 if (t->tx_timer_stk_next != nullptr)
2482 {
2484 }
2485
2486 t->tx_timer_stk_next = nullptr;
2487 t->tx_timer_stk_prev = nullptr;
2488}

References g_TimerHead, TimerListRemove(), TX_TIMER_STRUCT::tx_timer_stk_next, and TX_TIMER_STRUCT::tx_timer_stk_prev.

Referenced by anonymous_namespace{threadx_stk.cpp}::StkTimerThread::Run(), and TimerListRemove().

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

◆ ToStkTimeout()

__stk_forceinline stk::Timeout anonymous_namespace{threadx_stk.cpp}::ToStkTimeout ( ULONG wait_option)

Definition at line 79 of file threadx_stk.cpp.

80{
81 stk::Timeout result;
82
83 if (wait_option == TX_NO_WAIT)
84 {
85 result = stk::NO_WAIT;
86 }
87 else if (wait_option >= static_cast<ULONG>(stk::WAIT_INFINITE))
88 {
89 result = stk::WAIT_INFINITE;
90 }
91 else
92 {
93 result = static_cast<stk::Timeout>(wait_option);
94 }
95
96 return result;
97}
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:234

References __stk_forceinline, stk::NO_WAIT, ToStkTimeout(), TX_NO_WAIT, and stk::WAIT_INFINITE.

Referenced by QueueSend(), and ToStkTimeout().

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

◆ ToStkWeight()

__stk_forceinline stk::Weight anonymous_namespace{threadx_stk.cpp}::ToStkWeight ( UINT priority,
UINT threshold )

Definition at line 100 of file threadx_stk.cpp.

101{
102 return StkStrategy::FromThreadX(static_cast<uint8_t>(priority), static_cast<uint8_t>(threshold));
103}
static constexpr Weight FromThreadX(uint8_t tx_priority, uint8_t tx_threshold)

References __stk_forceinline, stk::SwitchStrategyPreemptionThreshold< 32, true >::FromThreadX(), and ToStkWeight().

Referenced by anonymous_namespace{threadx_stk.cpp}::StkTimerThread::GetWeight(), anonymous_namespace{threadx_stk.cpp}::StkThread::StkThread(), and ToStkWeight().

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

◆ WaitResultToTx()

__stk_forceinline UINT anonymous_namespace{threadx_stk.cpp}::WaitResultToTx ( stk::EWaitResult wr,
UINT timeout_status )

Definition at line 107 of file threadx_stk.cpp.

108{
109 UINT result;
110
111 switch (wr)
112 {
114 result = TX_SUCCESS;
115 break;
116
118 result = timeout_status;
119 break;
120
122 result = TX_WAIT_ABORTED;
123 break;
124
126 default:
127 result = TX_WAIT_ERROR;
128 break;
129 }
130
131 return result;
132}
#define TX_WAIT_ABORTED
Definition tx_api.h:204
@ WAIT_RESULT_FAIL
IKernelService::Wait returned with error without waiting.
Definition stk_common.h:138
@ WAIT_RESULT_CANCELED
The wait was cancelled by another task via IKernel::CancelTaskWait(), independent of signal/timeout.
Definition stk_common.h:141
@ WAIT_RESULT_TIMEOUT
The wake was caused by a timeout expiry.
Definition stk_common.h:140
@ WAIT_RESULT_SIGNAL
The wake was caused by a signal.
Definition stk_common.h:139

References __stk_forceinline, TX_SUCCESS, TX_WAIT_ABORTED, TX_WAIT_ERROR, stk::WAIT_RESULT_CANCELED, stk::WAIT_RESULT_FAIL, stk::WAIT_RESULT_SIGNAL, stk::WAIT_RESULT_TIMEOUT, and WaitResultToTx().

Referenced by QueueSend(), and WaitResultToTx().

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

◆ WaitThreadRemoved()

bool anonymous_namespace{threadx_stk.cpp}::WaitThreadRemoved ( const StkThread * th)

Definition at line 404 of file threadx_stk.cpp.

405{
406 // removal is processed by the kernel tick, a few ticks at most
407 for (uint32_t attempts = 0U; (!th->m_removed && (attempts < 1000U)); ++attempts)
408 {
409 if (!KernelRunning() || InIsr())
410 {
411 break;
412 }
413
414 stk::Sleep(1);
415 }
416
417 return th->m_removed;
418}
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:497

References InIsr(), KernelRunning(), anonymous_namespace{threadx_stk.cpp}::StkThread::m_removed, stk::Sleep(), and WaitThreadRemoved().

Referenced by WaitThreadRemoved().

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

Variable Documentation

◆ BLOCK_HDR_SIZE

const size_t anonymous_namespace{threadx_stk.cpp}::BLOCK_HDR_SIZE = sizeof(void *)

Definition at line 1936 of file threadx_stk.cpp.

◆ g_BytePools

StkBytePool* anonymous_namespace{threadx_stk.cpp}::g_BytePools = nullptr

Definition at line 2180 of file threadx_stk.cpp.

Referenced by BytePoolFind(), BytePoolLink(), and BytePoolUnlink().

◆ g_IntDisabled

volatile bool anonymous_namespace{threadx_stk.cpp}::g_IntDisabled = false

Definition at line 438 of file threadx_stk.cpp.

◆ g_TimeOffset

int64_t anonymous_namespace{threadx_stk.cpp}::g_TimeOffset = 0

Definition at line 465 of file threadx_stk.cpp.

◆ g_TimerEvent

stk::sync::Event anonymous_namespace{threadx_stk.cpp}::g_TimerEvent(false, false) ( false ,
false  )

◆ g_TimerHead

TX_TIMER* anonymous_namespace{threadx_stk.cpp}::g_TimerHead = nullptr

◆ g_TimerThread

StkTimerThread anonymous_namespace{threadx_stk.cpp}::g_TimerThread

Definition at line 2464 of file threadx_stk.cpp.

Referenced by EnsureTimerThread().

◆ g_TimerTid

stk::TId anonymous_namespace{threadx_stk.cpp}::g_TimerTid = stk::TID_NONE

Definition at line 61 of file threadx_stk.cpp.

Referenced by CurrentThread(), EnsureTimerThread(), and ThreadFromTid().