ChibiOS 21.11.4
ch_thread Struct Reference

Structure representing a thread. More...

#include <chobjects.h>

Collaboration diagram for ch_thread:
Collaboration graph

Data Fields

union { 
   ch_list_t   list 
 Threads lists element. More...
   ch_queue_t   queue 
 Threads queues element. More...
   ch_priority_queue_t   pqueue 
 Threads ordered queues element. More...
hdr
 Shared list headers.
struct port_context ctx
 Processor context.
ch_queue_t rqueue
 Registry queue element.
os_instance_towner
 OS instance owner of this thread.
const char * name
 Thread name or NULL.
stkalign_twabase
 Working area base address.
tstate_t state
 Current thread state.
tmode_t flags
 Various thread flags.
trefs_t refs
 References to this thread.
tslices_t ticks
 Number of ticks remaining to this thread.
volatile systime_t time
 Thread consumed time in ticks.
union { 
   msg_t   rdymsg 
 Thread wakeup code. More...
   msg_t   exitcode 
 Thread exit code. More...
   void *   wtobjp 
 Pointer to a generic "wait" object. More...
   thread_reference_t *   wttrp 
 Pointer to a generic thread reference object. More...
   msg_t   sentmsg 
 Thread sent message. More...
   struct ch_semaphore *   wtsemp 
 Pointer to a generic semaphore object. More...
   struct ch_mutex *   wtmtxp 
 Pointer to a generic mutex object. More...
   eventmask_t   ewmask 
 Enabled events mask. More...
u
 State-specific fields.
ch_list_t waiting
 Termination waiting list.
ch_queue_t msgqueue
 Messages queue.
eventmask_t epending
 Pending events mask.
struct ch_mutexmtxlist
 List of the mutexes owned by this thread.
tprio_t realprio
 Thread's own, non-inherited, priority.
void * mpool
 Memory Pool where the thread workspace is returned.
time_measurement_t stats
 Thread statistics.

Detailed Description

Structure representing a thread.

Note
Not all the listed fields are always needed, by switching off some not needed ChibiOS/RT subsystems it is possible to save RAM space by shrinking this structure.

Definition at line 156 of file chobjects.h.

Field Documentation

◆ list

ch_list_t ch_thread::list

Threads lists element.

Definition at line 164 of file chobjects.h.

Referenced by chThdWait().

◆ queue

ch_queue_t ch_thread::queue

Threads queues element.

Definition at line 168 of file chobjects.h.

Referenced by __sch_wakeup(), chCondWaitS(), chCondWaitTimeoutS(), and chMtxLockS().

◆ pqueue

◆ [union]

◆ ctx

struct port_context ch_thread::ctx

Processor context.

Definition at line 177 of file chobjects.h.

◆ rqueue

ch_queue_t ch_thread::rqueue

Registry queue element.

Definition at line 182 of file chobjects.h.

Referenced by chRegNextThread().

◆ owner

os_instance_t* ch_thread::owner

OS instance owner of this thread.

Definition at line 187 of file chobjects.h.

Referenced by __sch_ready_ahead(), __sch_ready_behind(), __thd_object_init(), chSchGoSleepS(), chSchReadyI(), and chSchWakeupS().

◆ name

const char* ch_thread::name

Thread name or NULL.

Definition at line 192 of file chobjects.h.

Referenced by __thd_object_init(), chRegGetThreadNameX(), and chRegSetThreadNameX().

◆ wabase

stkalign_t* ch_thread::wabase

Working area base address.

Note
This pointer is used for stack overflow checks and for dynamic threading.

Definition at line 201 of file chobjects.h.

Referenced by chInstanceObjectInit(), chThdCreateI(), chThdCreateStatic(), chThdCreateSuspendedI(), and chThdGetWorkingAreaX().

◆ state

◆ flags

tmode_t ch_thread::flags

◆ refs

trefs_t ch_thread::refs

References to this thread.

Definition at line 215 of file chobjects.h.

Referenced by __thd_object_init(), chRegFirstThread(), chRegNextThread(), chThdAddRef(), chThdExitS(), chThdRelease(), and chThdWait().

◆ ticks

tslices_t ch_thread::ticks

Number of ticks remaining to this thread.

Definition at line 221 of file chobjects.h.

Referenced by __sch_reschedule_behind(), __thd_object_init(), chSchDoPreemption(), chSchGoSleepS(), chSchIsPreemptionRequired(), chSchPreemption(), and chSysTimerHandlerI().

◆ time

volatile systime_t ch_thread::time

Thread consumed time in ticks.

Note
This field can overflow.

Definition at line 228 of file chobjects.h.

Referenced by __thd_object_init(), chSysTimerHandlerI(), and chThdGetTicksX().

◆ rdymsg

msg_t ch_thread::rdymsg

Thread wakeup code.

Note
This field contains the low level message sent to the thread by the waking thread or interrupt handler. The value is valid after exiting the chSchWakeupS() function.

Definition at line 242 of file chobjects.h.

Referenced by __sch_ready_ahead(), __sch_ready_behind(), __sch_wakeup(), chCondBroadcastI(), chCondSignalI(), chCondWaitS(), chEvtSignalI(), chMsgSend(), chSchGoSleepTimeoutS(), chSchWakeupS(), chSemAddCounterI(), chSemResetWithMessageI(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chThdDoDequeueNextI(), and chThdResumeI().

◆ exitcode

msg_t ch_thread::exitcode

Thread exit code.

Note
The thread termination code is stored in this field in order to be retrieved by the thread performing a chThdWait() on this thread.

Definition at line 249 of file chobjects.h.

Referenced by chThdExitS(), and chThdWait().

◆ wtobjp

void* ch_thread::wtobjp

Pointer to a generic "wait" object.

Note
This field is used to get a generic pointer to a synchronization object and is valid when the thread is in one of the wait states.

Definition at line 256 of file chobjects.h.

Referenced by __trace_switch(), chCondWaitS(), and chCondWaitTimeoutS().

◆ wttrp

thread_reference_t* ch_thread::wttrp

Pointer to a generic thread reference object.

Note
This field is used to get a pointer to a synchronization object and is valid when the thread is in CH_STATE_SUSPENDED state.

Definition at line 263 of file chobjects.h.

Referenced by __sch_wakeup(), chThdSuspendS(), and chThdSuspendTimeoutS().

◆ sentmsg

msg_t ch_thread::sentmsg

Thread sent message.

Definition at line 268 of file chobjects.h.

Referenced by chMsgGet(), and chMsgSend().

◆ wtsemp

struct ch_semaphore* ch_thread::wtsemp

Pointer to a generic semaphore object.

Note
This field is used to get a pointer to a synchronization object and is valid when the thread is in CH_STATE_WTSEM state.

Definition at line 277 of file chobjects.h.

Referenced by __sch_wakeup(), chSemSignalWait(), chSemWaitS(), and chSemWaitTimeoutS().

◆ wtmtxp

struct ch_mutex* ch_thread::wtmtxp

Pointer to a generic mutex object.

Note
This field is used to get a pointer to a synchronization object and is valid when the thread is in CH_STATE_WTMTX state.

Definition at line 286 of file chobjects.h.

Referenced by chMtxLockS().

◆ ewmask

eventmask_t ch_thread::ewmask

Enabled events mask.

Note
This field is only valid while the thread is in the CH_STATE_WTOREVT or CH_STATE_WTANDEVT states.

Definition at line 294 of file chobjects.h.

Referenced by chEvtSignalI(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOne(), and chEvtWaitOneTimeout().

◆ [union]

◆ waiting

ch_list_t ch_thread::waiting

Termination waiting list.

Definition at line 301 of file chobjects.h.

Referenced by __thd_object_init(), chThdExitS(), and chThdWait().

◆ msgqueue

ch_queue_t ch_thread::msgqueue

Messages queue.

Definition at line 307 of file chobjects.h.

Referenced by __thd_object_init(), chMsgIsPendingI(), chMsgPollS(), chMsgSend(), chMsgWaitS(), and chMsgWaitTimeoutS().

◆ epending

◆ mtxlist

struct ch_mutex* ch_thread::mtxlist

List of the mutexes owned by this thread.

Note
The list is terminated by a NULL in this field.

Definition at line 320 of file chobjects.h.

Referenced by __thd_object_init(), chMtxLockS(), chMtxTryLockS(), chMtxUnlock(), chMtxUnlockAllS(), and chMtxUnlockS().

◆ realprio

tprio_t ch_thread::realprio

Thread's own, non-inherited, priority.

Definition at line 324 of file chobjects.h.

Referenced by __thd_object_init(), chMtxUnlock(), chMtxUnlockAllS(), chMtxUnlockS(), and chThdSetPriority().

◆ mpool

void* ch_thread::mpool

Memory Pool where the thread workspace is returned.

Definition at line 331 of file chobjects.h.

Referenced by chThdCreateFromMemoryPool(), and chThdRelease().

◆ stats

time_measurement_t ch_thread::stats

Thread statistics.

Definition at line 337 of file chobjects.h.

Referenced by __stats_ctxswc(), __thd_object_init(), and chInstanceObjectInit().