Go to the documentation of this file.
39 #define MSG_OK (msg_t)0
40 #define MSG_TIMEOUT (msg_t)-1
42 #define MSG_RESET (msg_t)-2
50 #define NOPRIO (tprio_t)0
52 #define IDLEPRIO (tprio_t)1
53 #define LOWPRIO (tprio_t)2
54 #define NORMALPRIO (tprio_t)128
55 #define HIGHPRIO (tprio_t)255
62 #define CH_STATE_READY (tstate_t)0
64 #define CH_STATE_CURRENT (tstate_t)1
65 #define CH_STATE_WTSTART (tstate_t)2
66 #define CH_STATE_SUSPENDED (tstate_t)3
67 #define CH_STATE_QUEUED (tstate_t)4
68 #define CH_STATE_WTSEM (tstate_t)5
69 #define CH_STATE_WTMTX (tstate_t)6
70 #define CH_STATE_WTCOND (tstate_t)7
71 #define CH_STATE_SLEEPING (tstate_t)8
72 #define CH_STATE_WTEXIT (tstate_t)9
73 #define CH_STATE_WTOREVT (tstate_t)10
74 #define CH_STATE_WTANDEVT (tstate_t)11
75 #define CH_STATE_SNDMSGQ (tstate_t)12
77 #define CH_STATE_SNDMSG (tstate_t)13
79 #define CH_STATE_WTMSG (tstate_t)14
81 #define CH_STATE_FINAL (tstate_t)15
88 #define CH_STATE_NAMES \
89 "READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", \
90 "WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", \
91 "SNDMSG", "WTMSG", "FINAL"
98 #define CH_FLAG_MODE_MASK (tmode_t)3U
100 #define CH_FLAG_MODE_STATIC (tmode_t)0U
101 #define CH_FLAG_MODE_HEAP (tmode_t)1U
103 #define CH_FLAG_MODE_MPOOL (tmode_t)2U
105 #define CH_FLAG_TERMINATE (tmode_t)4U
142 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
147 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
153 #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
170 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
179 #if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
182 #if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__)
223 #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
229 #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
238 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
247 #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
256 #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
262 #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
268 #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
274 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
285 #if ((CH_CFG_USE_DYNAMIC == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE)) || \
292 #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
298 #if defined(CH_CFG_THREAD_EXTRA_FIELDS)
337 #if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
340 #if (CH_CFG_ST_TIMEDELTA > 0) || defined(__DOXYGEN__)
352 struct ch_ready_list {
361 struct port_context ctx;
362 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
391 #if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) || defined(__DOXYGEN__)
401 #if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
431 #if (CH_CFG_USE_TM == TRUE) || defined(__DOXYGEN__)
437 #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
455 #define firstprio(rlp) ((rlp)->next->prio)
462 #define currp ch.rlist.current
468 #if !defined(__DOXYGEN__)
489 #if CH_CFG_OPTIMIZE_SPEED == FALSE
502 #if CH_CFG_OPTIMIZE_SPEED == TRUE
508 }
while ((cp != qp) &&
578 tprio_t p2 =
currp->hdr.pqueue.prio;
580 #if CH_CFG_TIME_QUANTUM > 0
581 if (
currp->ticks > (tslices_t)0) {
static void chSchDoYieldS(void)
Yields the time slot.
static void chSchPreemption(void)
Inline-able preemption code.
void _scheduler_init(void)
Scheduler initialization.
thread_reference_t * wttrp
Pointer to a generic thread reference object.
ch_queue_t * next
Next in the list/queue.
thread_t * chSchReadyI(thread_t *tp)
Inserts a thread in the Ready List placing it behind its peers.
Type of a time measurement calibration data.
tprio_t realprio
Thread's own, non-inherited, priority.
eventmask_t epending
Pending events mask.
ch_priority_queue_t pqueue
Threads ordered queues element.
#define currp
Current thread pointer access macro.
thread_t * newer
Newer registry element.
msg_t rdymsg
Thread wakeup code.
Structure representing a threads queue.
uint64_t systime_t
Type of system time.
#define CH_CFG_SYSTEM_EXTRA_FIELDS
System structure extension.
struct ch_mutex * mtxlist
List of the mutexes owned by this thread.
virtual_timers_list_t vtlist
Virtual timers delta list header.
void ch_sch_prio_insert(ch_queue_t *tp, ch_queue_t *qp)
Inserts a thread into a priority ordered queue.
void chSchDoRescheduleBehind(void)
Switches to the first thread on the runnable queue.
delta_list_t dlist
Delta list element.
vtfunc_t func
Timer callback function pointer.
msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout)
Puts the current thread to sleep into the specified state with timeout specification.
static bool chSchIsRescRequiredI(void)
Determines if the current thread must reschedule.
void chSchDoReschedule(void)
Switches to the first thread on the runnable queue.
#define CH_CFG_THREAD_EXTRA_FIELDS
Threads descriptor structure extension.
struct ch_mutex * wtmtxp
Pointer to a generic mutex object.
trefs_t refs
References to this thread.
const char * name
Thread name or NULL.
msg_t sentmsg
Thread sent message.
Structure representing a thread.
void chSchGoSleepS(tstate_t newstate)
Puts the current thread to sleep into the specified state.
stkalign_t * wabase
Working area base address.
cnt_t isr_cnt
ISR nesting level.
Type of a Time Measurement object.
volatile systime_t systime
System Time counter.
tslices_t ticks
Number of ticks remaining to this thread.
sysinterval_t delta
Time delta before timeout.
System debug data structure.
eventmask_t ewmask
Enabled events mask.
delta_list_t * prev
Previous timer in the list.
ch_queue_t msgqueue
Messages queue.
thread_t mainthread
Main thread descriptor.
union ch_thread::@1 u
State-specific fields.
Structure representing a generic bidirectional linked list header and element.
delta_list_t dlist
Delta list header.
void * wtobjp
Pointer to a generic "wait" object.
struct ch_ready_list ready_list_t
Type of a ready list header.
void chSchRescheduleS(void)
Performs a reschedule if a higher priority thread is runnable.
#define firstprio(rlp)
Returns the priority of the first thread on the given ready list.
thread_t * older
Older registry element.
kernel_stats_t kernel_stats
Global kernel statistics.
void chDbgCheckClassI(void)
I-class functions context check.
Structure representing a Virtual Timer.
const char *volatile panic_msg
Pointer to the panic message.
volatile systime_t time
Thread consumed time in ticks.
cnt_t lock_cnt
Lock nesting level.
thread_t * chSchReadyAheadI(thread_t *tp)
Inserts a thread in the Ready List placing it ahead its peers.
bool chSchIsPreemptionRequired(void)
Evaluates if preemption is required.
struct port_context ctx
Processor context.
ch_system_t ch
System data structures.
uint64_t sysinterval_t
Type of time interval.
void chSchDoRescheduleAhead(void)
Switches to the first thread on the runnable queue.
void * mpool
Memory Pool where the thread workspace is returned.
Type of a kernel statistics structure.
ch_queue_t queue
Threads queues element.
tstate_t state
Current thread state.
struct ch_semaphore * wtsemp
Pointer to a generic semaphore object.
systime_t lasttime
System time of the last tick event.
Structure representing a virtual timers list header.
time_measurement_t stats
Thread statistics.
ch_trace_buffer_t trace_buffer
Public trace buffer.
ready_list_t rlist
Ready list header.
msg_t exitcode
Thread exit code.
ch_list_t waiting
Termination waiting list.
void(* vtfunc_t)(void *p)
Type of a Virtual Timer callback function.
void chDbgCheckClassS(void)
S-class functions context check.
void * par
Timer callback function parameter.
static bool chSchCanYieldS(void)
Determines if yielding is possible.
delta_list_t * next
Next timer in the list.
Structure representing a generic single link list header and element.
Structure representing a generic priority-ordered bidirectional linked list header and element.
ch_list_t list
Threads lists element.
Virtual Timer delta list element and header structure.
tmode_t flags
Various thread flags.
system_debug_t dbg
System debug.
tm_calibration_t tm
Time measurement calibration data.
void chSchWakeupS(thread_t *ntp, msg_t msg)
Wakes up a thread.
ch_queue_t queue
Threads queue header.