ChibiOS/RT Architecture - Reference Manual - Guides |
This module provides the default portable scheduler code, scheduler functions can be individually captured by the port layer in order to provide architecture optimized equivalents. When a function is captured its default code is not built into the OS image, the optimized version is included instead.
Data Structures | |
struct | ReadyList |
Ready list header. More... | |
Defines | |
#define | RDY_OK 0 |
Default thread wakeup low level message. | |
#define | RDY_TIMEOUT -1 |
Low level message sent to a thread awakened by a timeout. | |
#define | RDY_RESET -2 |
Low level message sent to a thread awakened by a reset operation. | |
#define | NOPRIO 0 |
Ready list header priority. | |
#define | IDLEPRIO 1 |
Idle thread priority. | |
#define | LOWPRIO 2 |
Lowest user priority. | |
#define | NORMALPRIO 64 |
Normal user priority. | |
#define | HIGHPRIO 127 |
Highest user priority. | |
#define | ABSPRIO 255 |
Greatest possible priority. | |
#define | TIME_IMMEDIATE ((systime_t)-1) |
Zero time specification for some syscalls with a timeout specification. | |
#define | TIME_INFINITE ((systime_t)0) |
Infinite time specification for all the syscalls with a timeout specification. | |
#define | firstprio(rlp) ((rlp)->p_next->p_prio) |
Returns the priority of the first thread on the given ready list. | |
#define | currp rlist.r_current |
Current thread pointer access macro. | |
#define | setcurrp(tp) (currp = (tp)) |
Current thread pointer change macro. | |
#define | chSchIsRescRequiredI() (firstprio(&rlist.r_queue) > currp->p_prio) |
Determines if the current thread must reschedule. | |
#define | chSchCanYieldS() (firstprio(&rlist.r_queue) >= currp->p_prio) |
Determines if yielding is possible. | |
#define | chSchDoYieldS() |
Yields the time slot. | |
Functions | |
void | scheduler_init (void) |
Scheduler initialization. | |
Thread * | chSchReadyI (Thread *tp) |
Inserts a thread in the Ready List. | |
void | chSchGoSleepS (tstate_t newstate) |
Puts the current thread to sleep into the specified state. | |
msg_t | chSchGoSleepTimeoutS (tstate_t newstate, systime_t time) |
Puts the current thread to sleep into the specified state with timeout specification. | |
void | chSchWakeupS (Thread *ntp, msg_t msg) |
Wakes up a thread. | |
void | chSchDoRescheduleI (void) |
Switches to the first thread on the runnable queue. | |
void | chSchRescheduleS (void) |
Performs a reschedule if a higher priority thread is runnable. | |
bool_t | chSchIsRescRequiredExI (void) |
Evaluates if a reschedule is required. | |
Variables | |
ReadyList | rlist |
Ready list header. |
#define RDY_OK 0 |
Default thread wakeup low level message.
Definition at line 39 of file chschd.h.
Referenced by adcWaitConversion(), canReceive(), canTransmit(), chCondSignal(), chCondSignalI(), chEvtSignalI(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chIQGetTimeout(), chIQReadTimeout(), chMBFetchS(), chMBPostAheadS(), chMBPostS(), chMtxUnlock(), chOQPutTimeout(), chOQWriteTimeout(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdResume(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().
#define RDY_TIMEOUT -1 |
Low level message sent to a thread awakened by a timeout.
Definition at line 41 of file chschd.h.
Referenced by adcWaitConversion(), chCondWaitTimeoutS(), chSemWaitTimeoutS(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().
#define RDY_RESET -2 |
Low level message sent to a thread awakened by a reset operation.
Definition at line 43 of file chschd.h.
Referenced by chCondBroadcastI(), and chSemResetI().
#define NOPRIO 0 |
#define IDLEPRIO 1 |
#define LOWPRIO 2 |
#define NORMALPRIO 64 |
#define HIGHPRIO 127 |
Highest user priority.
Definition at line 49 of file chschd.h.
Referenced by chThdInit(), and chThdSetPriority().
#define TIME_IMMEDIATE ((systime_t)-1) |
Zero time specification for some syscalls with a timeout specification.
TIME_IMMEDIATE
as timeout parameter, see the specific function documentation. Definition at line 58 of file chschd.h.
Referenced by chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), and chSemWaitTimeoutS().
#define TIME_INFINITE ((systime_t)0) |
Infinite time specification for all the syscalls with a timeout specification.
Definition at line 64 of file chschd.h.
Referenced by chSchGoSleepTimeoutS(), chThdSleep(), chVTSetI(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().
#define firstprio | ( | rlp | ) | ((rlp)->p_next->p_prio) |
Returns the priority of the first thread on the given ready list.
Definition at line 69 of file chschd.h.
Referenced by chSchIsRescRequiredExI().
#define currp rlist.r_current |
Current thread pointer access macro.
chThdSelf()
API instead. setcurrp()
instead. Definition at line 111 of file chschd.h.
Referenced by chCondWaitS(), chCondWaitTimeoutS(), chDbgTrace(), chEvtClear(), chEvtPend(), chEvtRegisterMask(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chMsgGet(), chMsgRelease(), chMsgSend(), chMsgWait(), chMtxLockS(), chMtxTryLockS(), chMtxUnlock(), chMtxUnlockAll(), chMtxUnlockS(), chSchDoRescheduleI(), chSchGoSleepS(), chSchGoSleepTimeoutS(), chSchIsRescRequiredExI(), chSchWakeupS(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chSysInit(), chSysTimerHandlerI(), chThdExit(), chThdSetPriority(), chThdWait(), and chibios_rt::BaseThread::IsPendingMessage().
#define setcurrp | ( | tp | ) | (currp = (tp)) |
Current thread pointer change macro.
Definition at line 123 of file chschd.h.
Referenced by chSchDoRescheduleI(), chSchGoSleepS(), chSchWakeupS(), and chSysInit().
#define chSchIsRescRequiredI | ( | ) | (firstprio(&rlist.r_queue) > currp->p_prio) |
Determines if the current thread must reschedule.
This function returns TRUE
if there is a ready thread with higher priority.
Definition at line 164 of file chschd.h.
Referenced by chSchRescheduleS().
#define chSchCanYieldS | ( | ) | (firstprio(&rlist.r_queue) >= currp->p_prio) |
#define chSchDoYieldS | ( | ) |
{ \ if (chSchCanYieldS()) \ chSchDoRescheduleI(); \ }
Yields the time slot.
Yields the CPU control to the next thread in the ready list with equal or higher priority, if any.
Definition at line 182 of file chschd.h.
Referenced by chThdYield().
void scheduler_init | ( | void | ) |
Scheduler initialization.
chSysInit()
, not an API. Definition at line 53 of file chschd.c.
References CH_TIME_QUANTUM, NOPRIO, queue_init, ReadyList::r_newer, ReadyList::r_older, ReadyList::r_prio, and ReadyList::r_queue.
Referenced by chSysInit().
Inserts a thread in the Ready List.
chSchRescheduleS()
should be called soon after.[in] | tp | the Thread to be made ready |
Definition at line 78 of file chschd.c.
References Thread::p_next, Thread::p_state, ReadyList::r_queue, and THD_STATE_READY.
Referenced by chCondBroadcastI(), chCondSignalI(), chEvtSignalI(), chMsgSend(), chMtxLockS(), chMtxUnlockAll(), chMtxUnlockS(), chSchDoRescheduleI(), chSchWakeupS(), chSemResetI(), chSemSignalI(), chSemSignalWait(), and chThdExit().
void chSchGoSleepS | ( | tstate_t | newstate | ) |
Puts the current thread to sleep into the specified state.
The thread goes into a sleeping state. The Threads States are described into threads.h
.
[in] | newstate | the new thread state |
Definition at line 102 of file chschd.c.
References CH_TIME_QUANTUM, chDbgTrace(), chSysSwitchI, currp, fifo_remove(), ReadyList::r_queue, setcurrp, and THD_STATE_CURRENT.
Referenced by chCondWaitS(), chEvtWaitAll(), chEvtWaitAny(), chEvtWaitOne(), chMsgSend(), chMsgWait(), chMtxLockS(), chSchGoSleepTimeoutS(), chSemSignalWait(), chSemWaitS(), chThdExit(), and chThdWait().
Puts the current thread to sleep into the specified state with timeout specification.
The thread goes into a sleeping state, if it is not awakened explicitly within the specified timeout then it is forcibly awakened with a RDY_TIMEOUT
low level message. The Threads States are described into threads.h
.
[in] | newstate | the new thread state |
[in] | time | the number of ticks before the operation timeouts, the special values are handled as follow:
|
RDY_TIMEOUT | if a timeout occurs. |
Definition at line 163 of file chschd.c.
References chSchGoSleepS(), chVTIsArmedI, chVTResetI(), chVTSetI(), currp, and TIME_INFINITE.
Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), and chSemWaitTimeoutS().
Wakes up a thread.
The thread is inserted into the ready list or immediately made running depending on its relative priority compared to the current thread.
chSchReadyI()
followed by a chSchRescheduleS()
but much more efficient. [in] | ntp | the Thread to be made ready |
[in] | msg | message to the awakened thread |
Definition at line 193 of file chschd.c.
References CH_TIME_QUANTUM, chDbgTrace(), chSchReadyI(), chSysSwitchI, currp, Thread::p_prio, Thread::p_state, Thread::p_u, Thread::rdymsg, setcurrp, and THD_STATE_CURRENT.
Referenced by chCondSignal(), chMsgRelease(), chMtxUnlock(), chSemSignal(), and chThdResume().
void chSchDoRescheduleI | ( | void | ) |
Switches to the first thread on the runnable queue.
chSchRescRequiredI()
evaluates to TRUE
. Definition at line 221 of file chschd.c.
References CH_TIME_QUANTUM, chDbgTrace(), chSchReadyI(), chSysSwitchI, currp, fifo_remove(), ReadyList::r_queue, setcurrp, and THD_STATE_CURRENT.
Referenced by chSchRescheduleS().
void chSchRescheduleS | ( | void | ) |
Performs a reschedule if a higher priority thread is runnable.
If a thread with a higher priority than the current thread is in the ready list then make the higher priority thread running.
Definition at line 243 of file chschd.c.
References chSchDoRescheduleI(), and chSchIsRescRequiredI.
Referenced by adcStopConversion(), canSleep(), canStop(), canWakeup(), chCondBroadcast(), chEvtBroadcast(), chEvtSignal(), chMBFetchS(), chMBPostAheadS(), chMBPostS(), chMBReset(), chMtxUnlockAll(), chSemReset(), chSemSignalWait(), chThdSetPriority(), and sdStop().
bool_t chSchIsRescRequiredExI | ( | void | ) |
Evaluates if a reschedule is required.
The decision is taken by comparing the relative priorities and depending on the state of the round robin timeout counter.
chVTDoTickI()
is invoked.TRUE | if there is a thread that should go in running state. | |
FALSE | if a reschedule is not required. |
Definition at line 261 of file chschd.c.
References currp, firstprio, and ReadyList::r_queue.
Ready list header.
Definition at line 46 of file chschd.c.
Referenced by chRegFirstThread(), chRegNextThread(), and chSysTimerHandlerI().