ChibiOS/RT  6.1.4
chschd.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
3  2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS.
6 
7  ChibiOS is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 3 of the License.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file rt/include/chschd.h
22  * @brief Scheduler macros and structures.
23  *
24  * @addtogroup scheduler
25  * @{
26  */
27 
28 #ifndef CHSCHD_H
29 #define CHSCHD_H
30 
31 /*===========================================================================*/
32 /* Module constants. */
33 /*===========================================================================*/
34 
35 /**
36  * @name Wakeup status codes
37  * @{
38  */
39 #define MSG_OK (msg_t)0 /**< @brief Normal wakeup message. */
40 #define MSG_TIMEOUT (msg_t)-1 /**< @brief Wakeup caused by a timeout
41  condition. */
42 #define MSG_RESET (msg_t)-2 /**< @brief Wakeup caused by a reset
43  condition. */
44 /** @} */
45 
46 /**
47  * @name Priority constants
48  * @{
49  */
50 #define NOPRIO (tprio_t)0 /**< @brief Ready list header
51  priority. */
52 #define IDLEPRIO (tprio_t)1 /**< @brief Idle priority. */
53 #define LOWPRIO (tprio_t)2 /**< @brief Lowest priority. */
54 #define NORMALPRIO (tprio_t)128 /**< @brief Normal priority. */
55 #define HIGHPRIO (tprio_t)255 /**< @brief Highest priority. */
56 /** @} */
57 
58 /**
59  * @name Thread states
60  * @{
61  */
62 #define CH_STATE_READY (tstate_t)0 /**< @brief Waiting on the
63  ready list. */
64 #define CH_STATE_CURRENT (tstate_t)1 /**< @brief Currently running. */
65 #define CH_STATE_WTSTART (tstate_t)2 /**< @brief Just created. */
66 #define CH_STATE_SUSPENDED (tstate_t)3 /**< @brief Suspended state. */
67 #define CH_STATE_QUEUED (tstate_t)4 /**< @brief On a queue. */
68 #define CH_STATE_WTSEM (tstate_t)5 /**< @brief On a semaphore. */
69 #define CH_STATE_WTMTX (tstate_t)6 /**< @brief On a mutex. */
70 #define CH_STATE_WTCOND (tstate_t)7 /**< @brief On a cond.variable.*/
71 #define CH_STATE_SLEEPING (tstate_t)8 /**< @brief Sleeping. */
72 #define CH_STATE_WTEXIT (tstate_t)9 /**< @brief Waiting a thread. */
73 #define CH_STATE_WTOREVT (tstate_t)10 /**< @brief One event. */
74 #define CH_STATE_WTANDEVT (tstate_t)11 /**< @brief Several events. */
75 #define CH_STATE_SNDMSGQ (tstate_t)12 /**< @brief Sending a message,
76  in queue. */
77 #define CH_STATE_SNDMSG (tstate_t)13 /**< @brief Sent a message,
78  waiting answer. */
79 #define CH_STATE_WTMSG (tstate_t)14 /**< @brief Waiting for a
80  message. */
81 #define CH_STATE_FINAL (tstate_t)15 /**< @brief Thread terminated. */
82 
83 /**
84  * @brief Thread states as array of strings.
85  * @details Each element in an array initialized with this macro can be
86  * indexed using the numeric thread state values.
87  */
88 #define CH_STATE_NAMES \
89  "READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", \
90  "WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", \
91  "SNDMSG", "WTMSG", "FINAL"
92 /** @} */
93 
94 /**
95  * @name Thread flags and attributes
96  * @{
97  */
98 #define CH_FLAG_MODE_MASK (tmode_t)3U /**< @brief Thread memory mode
99  mask. */
100 #define CH_FLAG_MODE_STATIC (tmode_t)0U /**< @brief Static thread. */
101 #define CH_FLAG_MODE_HEAP (tmode_t)1U /**< @brief Thread allocated
102  from a Memory Heap. */
103 #define CH_FLAG_MODE_MPOOL (tmode_t)2U /**< @brief Thread allocated
104  from a Memory Pool. */
105 #define CH_FLAG_TERMINATE (tmode_t)4U /**< @brief Termination requested
106  flag. */
107 /** @} */
108 
109 /*===========================================================================*/
110 /* Module pre-compile time settings. */
111 /*===========================================================================*/
112 
113 /*===========================================================================*/
114 /* Derived constants and error checks. */
115 /*===========================================================================*/
116 
117 /*===========================================================================*/
118 /* Module data structures and types. */
119 /*===========================================================================*/
120 
121 /**
122  * @brief Structure representing a threads queue.
123  */
125  ch_queue_t queue; /**< @brief Threads queue header. */
126 };
127 
128 /**
129  * @brief Structure representing a thread.
130  * @note Not all the listed fields are always needed, by switching off some
131  * not needed ChibiOS/RT subsystems it is possible to save RAM space
132  * by shrinking this structure.
133  */
134 struct ch_thread {
135  union {
136  ch_list_t list; /**< @brief Threads lists element. */
137  ch_queue_t queue; /**< @brief Threads queues element. */
138  ch_priority_queue_t pqueue; /**< @brief Threads ordered queues
139  element. */
140  } hdr;
141  struct port_context ctx; /**< @brief Processor context. */
142 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
143  thread_t *newer; /**< @brief Newer registry element. */
144  thread_t *older; /**< @brief Older registry element. */
145 #endif
146  /* End of the fields shared with the ReadyList structure. */
147 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
148  /**
149  * @brief Thread name or @p NULL.
150  */
151  const char *name;
152 #endif
153 #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
154  defined(__DOXYGEN__)
155  /**
156  * @brief Working area base address.
157  * @note This pointer is used for stack overflow checks and for
158  * dynamic threading.
159  */
160  stkalign_t *wabase;
161 #endif
162  /**
163  * @brief Current thread state.
164  */
165  tstate_t state;
166  /**
167  * @brief Various thread flags.
168  */
169  tmode_t flags;
170 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
171  /**
172  * @brief References to this thread.
173  */
174  trefs_t refs;
175 #endif
176  /**
177  * @brief Number of ticks remaining to this thread.
178  */
179 #if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
180  tslices_t ticks;
181 #endif
182 #if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__)
183  /**
184  * @brief Thread consumed time in ticks.
185  * @note This field can overflow.
186  */
187  volatile systime_t time;
188 #endif
189  /**
190  * @brief State-specific fields.
191  * @note All the fields declared in this union are only valid in the
192  * specified state or condition and are thus volatile.
193  */
194  union {
195  /**
196  * @brief Thread wakeup code.
197  * @note This field contains the low level message sent to the thread
198  * by the waking thread or interrupt handler. The value is valid
199  * after exiting the @p chSchWakeupS() function.
200  */
201  msg_t rdymsg;
202  /**
203  * @brief Thread exit code.
204  * @note The thread termination code is stored in this field in order
205  * to be retrieved by the thread performing a @p chThdWait() on
206  * this thread.
207  */
208  msg_t exitcode;
209  /**
210  * @brief Pointer to a generic "wait" object.
211  * @note This field is used to get a generic pointer to a synchronization
212  * object and is valid when the thread is in one of the wait
213  * states.
214  */
215  void *wtobjp;
216  /**
217  * @brief Pointer to a generic thread reference object.
218  * @note This field is used to get a pointer to a synchronization
219  * object and is valid when the thread is in @p CH_STATE_SUSPENDED
220  * state.
221  */
223 #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
224  /**
225  * @brief Thread sent message.
226  */
227  msg_t sentmsg;
228 #endif
229 #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
230  /**
231  * @brief Pointer to a generic semaphore object.
232  * @note This field is used to get a pointer to a synchronization
233  * object and is valid when the thread is in @p CH_STATE_WTSEM
234  * state.
235  */
237 #endif
238 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
239  /**
240  * @brief Pointer to a generic mutex object.
241  * @note This field is used to get a pointer to a synchronization
242  * object and is valid when the thread is in @p CH_STATE_WTMTX
243  * state.
244  */
245  struct ch_mutex *wtmtxp;
246 #endif
247 #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
248  /**
249  * @brief Enabled events mask.
250  * @note This field is only valid while the thread is in the
251  * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
252  */
253  eventmask_t ewmask;
254 #endif
255  } u;
256 #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
257  /**
258  * @brief Termination waiting list.
259  */
261 #endif
262 #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
263  /**
264  * @brief Messages queue.
265  */
267 #endif
268 #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
269  /**
270  * @brief Pending events mask.
271  */
272  eventmask_t epending;
273 #endif
274 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
275  /**
276  * @brief List of the mutexes owned by this thread.
277  * @note The list is terminated by a @p NULL in this field.
278  */
279  struct ch_mutex *mtxlist;
280  /**
281  * @brief Thread's own, non-inherited, priority.
282  */
283  tprio_t realprio;
284 #endif
285 #if ((CH_CFG_USE_DYNAMIC == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE)) || \
286  defined(__DOXYGEN__)
287  /**
288  * @brief Memory Pool where the thread workspace is returned.
289  */
290  void *mpool;
291 #endif
292 #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
293  /**
294  * @brief Thread statistics.
295  */
297 #endif
298 #if defined(CH_CFG_THREAD_EXTRA_FIELDS)
299  /* Extra fields defined in chconf.h.*/
301 #endif
302 };
303 
304 /**
305  * @brief Type of a Virtual Timer structure.
306  */
308 
309 /**
310  * @brief Virtual Timer delta list element and header structure.
311  */
313  delta_list_t *next; /**< @brief Next timer in the list. */
314  delta_list_t *prev; /**< @brief Previous timer in the list. */
315  sysinterval_t delta; /**< @brief Time delta before timeout. */
316 };
317 
318 /**
319  * @brief Structure representing a Virtual Timer.
320  */
322  delta_list_t dlist; /**< @brief Delta list element. */
323  vtfunc_t func; /**< @brief Timer callback function
324  pointer. */
325  void *par; /**< @brief Timer callback function
326  parameter. */
327 };
328 
329 /**
330  * @brief Structure representing a virtual timers list header.
331  * @note The timers list is implemented as a double link bidirectional list
332  * in order to make the unlink time constant, the reset of a virtual
333  * timer is often used in the code.
334  */
336  delta_list_t dlist; /**< @brief Delta list header. */
337 #if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
338  volatile systime_t systime; /**< @brief System Time counter. */
339 #endif
340 #if (CH_CFG_ST_TIMEDELTA > 0) || defined(__DOXYGEN__)
341  /**
342  * @brief System time of the last tick event.
343  */
344  systime_t lasttime; /**< @brief System time of the last
345  tick event. */
346 #endif
347 };
348 
349 /**
350  * @extends threads_queue_t
351  */
352 struct ch_ready_list {
353  /**
354  * @brief Threads ordered queues header.
355  * @note The priority field must be initialized to zero.
356  */
357  ch_priority_queue_t pqueue;
358  /**
359  * @brief Not used, present because offsets.
360  */
361  struct port_context ctx;
362 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
363  /**
364  * @brief Newer registry element.
365  */
366  thread_t *newer;
367  /**
368  * @brief Older registry element.
369  */
370  thread_t *older;
371 #endif
372  /* End of the fields shared with the thread_t structure.*/
373  /**
374  * @brief The currently running thread.
375  */
376  thread_t *current;
377 };
378 
379 /**
380  * @brief System debug data structure.
381  */
383  /**
384  * @brief Pointer to the panic message.
385  * @details This pointer is meant to be accessed through the debugger, it is
386  * written once and then the system is halted.
387  * @note Accesses to this pointer must never be optimized out so the
388  * field itself is declared volatile.
389  */
390  const char * volatile panic_msg;
391 #if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) || defined(__DOXYGEN__)
392  /**
393  * @brief ISR nesting level.
394  */
395  cnt_t isr_cnt;
396  /**
397  * @brief Lock nesting level.
398  */
399  cnt_t lock_cnt;
400 #endif
401 #if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
402  /**
403  * @brief Public trace buffer.
404  */
406 #endif
407 };
408 
409 /**
410  * @brief System data structure.
411  * @note This structure contain all the data areas used by the OS except
412  * stacks.
413  */
414 struct ch_system {
415  /**
416  * @brief Ready list header.
417  */
419  /**
420  * @brief Virtual timers delta list header.
421  */
423  /**
424  * @brief System debug.
425  */
427  /**
428  * @brief Main thread descriptor.
429  */
431 #if (CH_CFG_USE_TM == TRUE) || defined(__DOXYGEN__)
432  /**
433  * @brief Time measurement calibration data.
434  */
436 #endif
437 #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
438  /**
439  * @brief Global kernel statistics.
440  */
442 #endif
444 };
445 
446 /*===========================================================================*/
447 /* Module macros. */
448 /*===========================================================================*/
449 
450 /**
451  * @brief Returns the priority of the first thread on the given ready list.
452  *
453  * @notapi
454  */
455 #define firstprio(rlp) ((rlp)->next->prio)
456 
457 /**
458  * @brief Current thread pointer access macro.
459  * @note This macro is not meant to be used in the application code but
460  * only from within the kernel, use @p chThdGetSelfX() instead.
461  */
462 #define currp ch.rlist.current
463 
464 /*===========================================================================*/
465 /* External declarations. */
466 /*===========================================================================*/
467 
468 #if !defined(__DOXYGEN__)
469 extern ch_system_t ch;
470 #endif
471 
472 /*
473  * Scheduler APIs.
474  */
475 #ifdef __cplusplus
476 extern "C" {
477 #endif
478  void _scheduler_init(void);
481  void chSchGoSleepS(tstate_t newstate);
482  msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout);
483  void chSchWakeupS(thread_t *ntp, msg_t msg);
484  void chSchRescheduleS(void);
485  bool chSchIsPreemptionRequired(void);
486  void chSchDoRescheduleBehind(void);
487  void chSchDoRescheduleAhead(void);
488  void chSchDoReschedule(void);
489 #if CH_CFG_OPTIMIZE_SPEED == FALSE
491 #endif /* CH_CFG_OPTIMIZE_SPEED == FALSE */
492 #ifdef __cplusplus
493 }
494 #endif
495 
496 /*===========================================================================*/
497 /* Module inline functions. */
498 /*===========================================================================*/
499 
500 /* If the performance code path has been chosen then all the following
501  functions are inlined into the various kernel modules.*/
502 #if CH_CFG_OPTIMIZE_SPEED == TRUE
503 static inline void ch_sch_prio_insert(ch_queue_t *tp, ch_queue_t *qp) {
504 
505  ch_queue_t *cp = qp;
506  do {
507  cp = cp->next;
508  } while ((cp != qp) &&
509  (((thread_t *)cp)->hdr.pqueue.prio >= ((thread_t *)tp)->hdr.pqueue.prio));
510  tp->next = cp;
511  tp->prev = cp->prev;
512  tp->prev->next = tp;
513  cp->prev = tp;
514 }
515 #endif /* CH_CFG_OPTIMIZE_SPEED == TRUE */
516 
517 /**
518  * @brief Determines if the current thread must reschedule.
519  * @details This function returns @p true if there is a ready thread with
520  * higher priority.
521  *
522  * @return The priorities situation.
523  * @retval false if rescheduling is not necessary.
524  * @retval true if there is a ready thread at higher priority.
525  *
526  * @iclass
527  */
528 static inline bool chSchIsRescRequiredI(void) {
529 
531 
532  return firstprio(&ch.rlist.pqueue) > currp->hdr.pqueue.prio;
533 }
534 
535 /**
536  * @brief Determines if yielding is possible.
537  * @details This function returns @p true if there is a ready thread with
538  * equal or higher priority.
539  *
540  * @return The priorities situation.
541  * @retval false if yielding is not possible.
542  * @retval true if there is a ready thread at equal or higher priority.
543  *
544  * @sclass
545  */
546 static inline bool chSchCanYieldS(void) {
547 
549 
550  return firstprio(&ch.rlist.pqueue) >= currp->hdr.pqueue.prio;
551 }
552 
553 /**
554  * @brief Yields the time slot.
555  * @details Yields the CPU control to the next thread in the ready list with
556  * equal or higher priority, if any.
557  *
558  * @sclass
559  */
560 static inline void chSchDoYieldS(void) {
561 
563 
564  if (chSchCanYieldS()) {
566  }
567 }
568 
569 /**
570  * @brief Inline-able preemption code.
571  * @details This is the common preemption code, this function must be invoked
572  * exclusively from the port layer.
573  *
574  * @special
575  */
576 static inline void chSchPreemption(void) {
577  tprio_t p1 = firstprio(&ch.rlist.pqueue);
578  tprio_t p2 = currp->hdr.pqueue.prio;
579 
580 #if CH_CFG_TIME_QUANTUM > 0
581  if (currp->ticks > (tslices_t)0) {
582  if (p1 > p2) {
584  }
585  }
586  else {
587  if (p1 >= p2) {
589  }
590  }
591 #else /* CH_CFG_TIME_QUANTUM == 0 */
592  if (p1 > p2) {
594  }
595 #endif /* CH_CFG_TIME_QUANTUM == 0 */
596 }
597 
598 #endif /* CHSCHD_H */
599 
600 /** @} */
chSchDoYieldS
static void chSchDoYieldS(void)
Yields the time slot.
Definition: chschd.h:560
chSchPreemption
static void chSchPreemption(void)
Inline-able preemption code.
Definition: chschd.h:576
_scheduler_init
void _scheduler_init(void)
Scheduler initialization.
Definition: chschd.c:128
ch_thread::wttrp
thread_reference_t * wttrp
Pointer to a generic thread reference object.
Definition: chschd.h:222
ch_queue::next
ch_queue_t * next
Next in the list/queue.
Definition: chlists.h:70
chSchReadyI
thread_t * chSchReadyI(thread_t *tp)
Inserts a thread in the Ready List placing it behind its peers.
Definition: chschd.c:153
tm_calibration_t
Type of a time measurement calibration data.
Definition: chtm.h:56
ch_thread::realprio
tprio_t realprio
Thread's own, non-inherited, priority.
Definition: chschd.h:283
ch_thread::epending
eventmask_t epending
Pending events mask.
Definition: chschd.h:272
ch_thread::pqueue
ch_priority_queue_t pqueue
Threads ordered queues element.
Definition: chschd.h:138
currp
#define currp
Current thread pointer access macro.
Definition: chschd.h:462
ch_thread::newer
thread_t * newer
Newer registry element.
Definition: chschd.h:143
ch_thread::rdymsg
msg_t rdymsg
Thread wakeup code.
Definition: chschd.h:201
ch_threads_queue
Structure representing a threads queue.
Definition: chschd.h:124
systime_t
uint64_t systime_t
Type of system time.
Definition: chtime.h:107
CH_CFG_SYSTEM_EXTRA_FIELDS
#define CH_CFG_SYSTEM_EXTRA_FIELDS
System structure extension.
Definition: chconf.h:633
ch_thread::mtxlist
struct ch_mutex * mtxlist
List of the mutexes owned by this thread.
Definition: chschd.h:279
ch_system::vtlist
virtual_timers_list_t vtlist
Virtual timers delta list header.
Definition: chschd.h:422
ch_sch_prio_insert
void ch_sch_prio_insert(ch_queue_t *tp, ch_queue_t *qp)
Inserts a thread into a priority ordered queue.
Definition: chschd.c:109
chSchDoRescheduleBehind
void chSchDoRescheduleBehind(void)
Switches to the first thread on the runnable queue.
Definition: chschd.c:390
ch_virtual_timer::dlist
delta_list_t dlist
Delta list element.
Definition: chschd.h:322
ch_virtual_timer::func
vtfunc_t func
Timer callback function pointer.
Definition: chschd.h:323
chSchGoSleepTimeoutS
msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout)
Puts the current thread to sleep into the specified state with timeout specification.
Definition: chschd.c:258
chSchIsRescRequiredI
static bool chSchIsRescRequiredI(void)
Determines if the current thread must reschedule.
Definition: chschd.h:528
chSchDoReschedule
void chSchDoReschedule(void)
Switches to the first thread on the runnable queue.
Definition: chschd.c:453
CH_CFG_THREAD_EXTRA_FIELDS
#define CH_CFG_THREAD_EXTRA_FIELDS
Threads descriptor structure extension.
Definition: chconf.h:649
ch_thread::wtmtxp
struct ch_mutex * wtmtxp
Pointer to a generic mutex object.
Definition: chschd.h:245
ch_thread::refs
trefs_t refs
References to this thread.
Definition: chschd.h:174
ch_thread::name
const char * name
Thread name or NULL.
Definition: chschd.h:151
ch_system
System data structure.
Definition: chschd.h:414
ch_thread::sentmsg
msg_t sentmsg
Thread sent message.
Definition: chschd.h:227
ch_thread
Structure representing a thread.
Definition: chschd.h:134
chSchGoSleepS
void chSchGoSleepS(tstate_t newstate)
Puts the current thread to sleep into the specified state.
Definition: chschd.c:210
ch_thread::wabase
stkalign_t * wabase
Working area base address.
Definition: chschd.h:160
ch_system_debug::isr_cnt
cnt_t isr_cnt
ISR nesting level.
Definition: chschd.h:395
time_measurement_t
Type of a Time Measurement object.
Definition: chtm.h:72
ch_virtual_timers_list::systime
volatile systime_t systime
System Time counter.
Definition: chschd.h:338
ch_thread::ticks
tslices_t ticks
Number of ticks remaining to this thread.
Definition: chschd.h:180
ch_delta_list::delta
sysinterval_t delta
Time delta before timeout.
Definition: chschd.h:315
ch_system_debug
System debug data structure.
Definition: chschd.h:382
ch_thread::ewmask
eventmask_t ewmask
Enabled events mask.
Definition: chschd.h:253
ch_semaphore
Semaphore structure.
Definition: chsem.h:52
ch_delta_list::prev
delta_list_t * prev
Previous timer in the list.
Definition: chschd.h:314
ch_thread::msgqueue
ch_queue_t msgqueue
Messages queue.
Definition: chschd.h:266
ch_system::mainthread
thread_t mainthread
Main thread descriptor.
Definition: chschd.h:430
ch_thread::u
union ch_thread::@1 u
State-specific fields.
ch_queue
Structure representing a generic bidirectional linked list header and element.
Definition: chlists.h:69
ch_virtual_timers_list::dlist
delta_list_t dlist
Delta list header.
Definition: chschd.h:336
ch_thread::wtobjp
void * wtobjp
Pointer to a generic "wait" object.
Definition: chschd.h:215
ready_list_t
struct ch_ready_list ready_list_t
Type of a ready list header.
Definition: chsystypes.h:76
chSchRescheduleS
void chSchRescheduleS(void)
Performs a reschedule if a higher priority thread is runnable.
Definition: chschd.c:339
firstprio
#define firstprio(rlp)
Returns the priority of the first thread on the given ready list.
Definition: chschd.h:455
ch_thread::older
thread_t * older
Older registry element.
Definition: chschd.h:144
ch_system::kernel_stats
kernel_stats_t kernel_stats
Global kernel statistics.
Definition: chschd.h:441
chDbgCheckClassI
void chDbgCheckClassI(void)
I-class functions context check.
Definition: chdebug.c:233
ch_virtual_timer
Structure representing a Virtual Timer.
Definition: chschd.h:321
ch_system_debug::panic_msg
const char *volatile panic_msg
Pointer to the panic message.
Definition: chschd.h:390
ch_thread::time
volatile systime_t time
Thread consumed time in ticks.
Definition: chschd.h:187
ch_system_debug::lock_cnt
cnt_t lock_cnt
Lock nesting level.
Definition: chschd.h:399
chSchReadyAheadI
thread_t * chSchReadyAheadI(thread_t *tp)
Inserts a thread in the Ready List placing it ahead its peers.
Definition: chschd.c:185
chSchIsPreemptionRequired
bool chSchIsPreemptionRequired(void)
Evaluates if preemption is required.
Definition: chschd.c:362
ch_thread::ctx
struct port_context ctx
Processor context.
Definition: chschd.h:141
ch_mutex
Mutex structure.
Definition: chmtx.h:57
ch
ch_system_t ch
System data structures.
Definition: chschd.c:42
sysinterval_t
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
chSchDoRescheduleAhead
void chSchDoRescheduleAhead(void)
Switches to the first thread on the runnable queue.
Definition: chschd.c:423
ch_thread::mpool
void * mpool
Memory Pool where the thread workspace is returned.
Definition: chschd.h:290
kernel_stats_t
Type of a kernel statistics structure.
Definition: chstats.h:56
ch_thread::queue
ch_queue_t queue
Threads queues element.
Definition: chschd.h:137
ch_thread::state
tstate_t state
Current thread state.
Definition: chschd.h:165
ch_thread::wtsemp
struct ch_semaphore * wtsemp
Pointer to a generic semaphore object.
Definition: chschd.h:236
ch_virtual_timers_list::lasttime
systime_t lasttime
System time of the last tick event.
Definition: chschd.h:344
ch_virtual_timers_list
Structure representing a virtual timers list header.
Definition: chschd.h:335
ch_thread::stats
time_measurement_t stats
Thread statistics.
Definition: chschd.h:296
ch_system_debug::trace_buffer
ch_trace_buffer_t trace_buffer
Public trace buffer.
Definition: chschd.h:405
ch_system::rlist
ready_list_t rlist
Ready list header.
Definition: chschd.h:418
ch_thread::exitcode
msg_t exitcode
Thread exit code.
Definition: chschd.h:208
ch_thread::waiting
ch_list_t waiting
Termination waiting list.
Definition: chschd.h:260
vtfunc_t
void(* vtfunc_t)(void *p)
Type of a Virtual Timer callback function.
Definition: chsystypes.h:81
chDbgCheckClassS
void chDbgCheckClassS(void)
S-class functions context check.
Definition: chdebug.c:248
ch_virtual_timer::par
void * par
Timer callback function parameter.
Definition: chschd.h:325
chSchCanYieldS
static bool chSchCanYieldS(void)
Determines if yielding is possible.
Definition: chschd.h:546
ch_delta_list::next
delta_list_t * next
Next timer in the list.
Definition: chschd.h:313
ch_list
Structure representing a generic single link list header and element.
Definition: chlists.h:56
ch_priority_queue
Structure representing a generic priority-ordered bidirectional linked list header and element.
Definition: chlists.h:85
ch_thread::list
ch_list_t list
Threads lists element.
Definition: chschd.h:136
ch_delta_list
Virtual Timer delta list element and header structure.
Definition: chschd.h:312
ch_thread::flags
tmode_t flags
Various thread flags.
Definition: chschd.h:169
ch_system::dbg
system_debug_t dbg
System debug.
Definition: chschd.h:426
ch_system::tm
tm_calibration_t tm
Time measurement calibration data.
Definition: chschd.h:435
chSchWakeupS
void chSchWakeupS(thread_t *ntp, msg_t msg)
Wakes up a thread.
Definition: chschd.c:295
ch_trace_buffer_t
Trace buffer header.
Definition: chtrace.h:175
ch_threads_queue::queue
ch_queue_t queue
Threads queue header.
Definition: chschd.h:125