ChibiOS/RT  5.1.0
Collaboration diagram for Scheduler:

Detailed Description

This module provides the default portable scheduler code.

Macros

#define firstprio(rlp)   ((rlp)->next->prio)
 Returns the priority of the first thread on the given ready list. More...
 
#define currp   ch.rlist.current
 Current thread pointer access macro. More...
 
#define __CH_STRINGIFY(a)   #a
 Utility to make the parameter a quoted string. More...
 

Wakeup status codes

#define MSG_OK   (msg_t)0
 Normal wakeup message. More...
 
#define MSG_TIMEOUT   (msg_t)-1
 Wakeup caused by a timeout condition. More...
 
#define MSG_RESET   (msg_t)-2
 Wakeup caused by a reset condition. More...
 

Priority constants

#define NOPRIO   (tprio_t)0
 Ready list header priority. More...
 
#define IDLEPRIO   (tprio_t)1
 Idle priority. More...
 
#define LOWPRIO   (tprio_t)2
 Lowest priority. More...
 
#define NORMALPRIO   (tprio_t)128
 Normal priority. More...
 
#define HIGHPRIO   (tprio_t)255
 Highest priority. More...
 

Thread states

#define CH_STATE_READY   (tstate_t)0
 Waiting on the ready list. More...
 
#define CH_STATE_CURRENT   (tstate_t)1
 Currently running. More...
 
#define CH_STATE_WTSTART   (tstate_t)2
 Just created. More...
 
#define CH_STATE_SUSPENDED   (tstate_t)3
 Suspended state. More...
 
#define CH_STATE_QUEUED   (tstate_t)4
 On a queue. More...
 
#define CH_STATE_WTSEM   (tstate_t)5
 On a semaphore. More...
 
#define CH_STATE_WTMTX   (tstate_t)6
 On a mutex. More...
 
#define CH_STATE_WTCOND   (tstate_t)7
 On a cond.variable. More...
 
#define CH_STATE_SLEEPING   (tstate_t)8
 Sleeping. More...
 
#define CH_STATE_WTEXIT   (tstate_t)9
 Waiting a thread. More...
 
#define CH_STATE_WTOREVT   (tstate_t)10
 One event. More...
 
#define CH_STATE_WTANDEVT   (tstate_t)11
 Several events. More...
 
#define CH_STATE_SNDMSGQ   (tstate_t)12
 Sending a message, in queue. More...
 
#define CH_STATE_SNDMSG   (tstate_t)13
 Sent a message, waiting answer. More...
 
#define CH_STATE_WTMSG   (tstate_t)14
 Waiting for a message. More...
 
#define CH_STATE_FINAL   (tstate_t)15
 Thread terminated. More...
 
#define CH_STATE_NAMES
 Thread states as array of strings. More...
 

Thread flags and attributes

#define CH_FLAG_MODE_MASK   (tmode_t)3U
 Thread memory mode mask. More...
 
#define CH_FLAG_MODE_STATIC   (tmode_t)0U
 Static thread. More...
 
#define CH_FLAG_MODE_HEAP   (tmode_t)1U
 Thread allocated from a Memory Heap. More...
 
#define CH_FLAG_MODE_MPOOL   (tmode_t)2U
 Thread allocated from a Memory Pool. More...
 
#define CH_FLAG_TERMINATE   (tmode_t)4U
 Termination requested flag. More...
 

Typedefs

typedef struct ch_thread thread_t
 Type of a thread structure. More...
 
typedef thread_tthread_reference_t
 Type of a thread reference. More...
 
typedef struct ch_threads_list threads_list_t
 Type of a generic threads single link list, it works like a stack. More...
 
typedef struct ch_threads_queue threads_queue_t
 Type of a generic threads bidirectional linked list header and element. More...
 
typedef struct ch_ready_list ready_list_t
 Type of a ready list header. More...
 
typedef void(* vtfunc_t) (void *p)
 Type of a Virtual Timer callback function. More...
 
typedef struct ch_virtual_timer virtual_timer_t
 Type of a Virtual Timer structure. More...
 
typedef struct ch_virtual_timers_list virtual_timers_list_t
 Type of virtual timers list header. More...
 
typedef struct ch_system_debug system_debug_t
 Type of a system debug structure. More...
 
typedef struct ch_system ch_system_t
 Type of system data structure. More...
 

Data Structures

struct  ch_threads_list
 Generic threads single link list, it works like a stack. More...
 
struct  ch_threads_queue
 Generic threads bidirectional linked list header and element. More...
 
struct  ch_thread
 Structure representing a thread. More...
 
struct  ch_virtual_timer
 Virtual Timer descriptor structure. More...
 
struct  ch_virtual_timers_list
 Virtual timers list header. More...
 
struct  ch_system_debug
 System debug data structure. More...
 
struct  ch_system
 System data structure. More...
 

Functions

void _scheduler_init (void)
 Scheduler initialization. More...
 
void queue_prio_insert (thread_t *tp, threads_queue_t *tqp)
 Inserts a thread into a priority ordered queue. More...
 
void queue_insert (thread_t *tp, threads_queue_t *tqp)
 Inserts a thread into a queue. More...
 
thread_tqueue_fifo_remove (threads_queue_t *tqp)
 Removes the first-out thread from a queue and returns it. More...
 
thread_tqueue_lifo_remove (threads_queue_t *tqp)
 Removes the last-out thread from a queue and returns it. More...
 
thread_tqueue_dequeue (thread_t *tp)
 Removes a thread from a queue and returns it. More...
 
void list_insert (thread_t *tp, threads_list_t *tlp)
 Pushes a thread_t on top of a stack list. More...
 
thread_tlist_remove (threads_list_t *tlp)
 Pops a thread from the top of a stack list and returns it. More...
 
thread_tchSchReadyI (thread_t *tp)
 Inserts a thread in the Ready List placing it behind its peers. More...
 
thread_tchSchReadyAheadI (thread_t *tp)
 Inserts a thread in the Ready List placing it ahead its peers. More...
 
void chSchGoSleepS (tstate_t newstate)
 Puts the current thread to sleep into the specified state. More...
 
msg_t chSchGoSleepTimeoutS (tstate_t newstate, sysinterval_t timeout)
 Puts the current thread to sleep into the specified state with timeout specification. More...
 
void chSchWakeupS (thread_t *ntp, msg_t msg)
 Wakes up a thread. More...
 
void chSchRescheduleS (void)
 Performs a reschedule if a higher priority thread is runnable. More...
 
bool chSchIsPreemptionRequired (void)
 Evaluates if preemption is required. More...
 
void chSchDoRescheduleBehind (void)
 Switches to the first thread on the runnable queue. More...
 
void chSchDoRescheduleAhead (void)
 Switches to the first thread on the runnable queue. More...
 
void chSchDoReschedule (void)
 Switches to the first thread on the runnable queue. More...
 
static void list_init (threads_list_t *tlp)
 Threads list initialization. More...
 
static bool list_isempty (threads_list_t *tlp)
 Evaluates to true if the specified threads list is empty. More...
 
static bool list_notempty (threads_list_t *tlp)
 Evaluates to true if the specified threads list is not empty. More...
 
static void queue_init (threads_queue_t *tqp)
 Threads queue initialization. More...
 
static bool queue_isempty (const threads_queue_t *tqp)
 Evaluates to true if the specified threads queue is empty. More...
 
static bool queue_notempty (const threads_queue_t *tqp)
 Evaluates to true if the specified threads queue is not empty. More...
 
static bool chSchIsRescRequiredI (void)
 Determines if the current thread must reschedule. More...
 
static bool chSchCanYieldS (void)
 Determines if yielding is possible. More...
 
static void chSchDoYieldS (void)
 Yields the time slot. More...
 
static void chSchPreemption (void)
 Inline-able preemption code. More...
 

Variables

ch_system_t ch
 System data structures. More...
 

Macro Definition Documentation

#define MSG_TIMEOUT   (msg_t)-1

Wakeup caused by a timeout condition.

Definition at line 40 of file chschd.h.

Referenced by chCondWaitTimeoutS(), chMBFetchI(), chMBPostAheadI(), chMBPostI(), chSchGoSleepS(), chSemWaitTimeoutS(), chThdEnqueueTimeoutS(), and chThdSuspendTimeoutS().

#define MSG_RESET   (msg_t)-2

Wakeup caused by a reset condition.

Definition at line 43 of file chschd.h.

Referenced by chCondBroadcastI(), chMBFetchI(), chMBFetchTimeoutS(), chMBPostAheadI(), chMBPostAheadTimeoutS(), chMBPostI(), chMBPostTimeoutS(), chMBResetI(), and chSemResetI().

#define NOPRIO   (tprio_t)0

Ready list header priority.

Definition at line 52 of file chschd.h.

Referenced by _scheduler_init().

#define IDLEPRIO   (tprio_t)1
#define LOWPRIO   (tprio_t)2

Lowest priority.

Definition at line 56 of file chschd.h.

#define NORMALPRIO   (tprio_t)128

Normal priority.

Definition at line 57 of file chschd.h.

Referenced by chSysInit().

#define HIGHPRIO   (tprio_t)255

Highest priority.

Definition at line 58 of file chschd.h.

Referenced by chThdCreateStatic(), chThdCreateSuspendedI(), and chThdSetPriority().

#define CH_STATE_READY   (tstate_t)0

Waiting on the ready list.

Definition at line 65 of file chschd.h.

Referenced by chMtxLockS(), chSchGoSleepS(), chSchReadyAheadI(), and chSchReadyI().

#define CH_STATE_CURRENT   (tstate_t)1
#define CH_STATE_WTSTART   (tstate_t)2

Just created.

Definition at line 69 of file chschd.h.

Referenced by _thread_init(), chThdStart(), and chThdStartI().

#define CH_STATE_SUSPENDED   (tstate_t)3

Suspended state.

Definition at line 70 of file chschd.h.

Referenced by chSchGoSleepS(), chThdResumeI(), chThdResumeS(), chThdSuspendS(), and chThdSuspendTimeoutS().

#define CH_STATE_QUEUED   (tstate_t)4

On a queue.

Definition at line 71 of file chschd.h.

Referenced by chSchGoSleepS(), chThdDoDequeueNextI(), and chThdEnqueueTimeoutS().

#define CH_STATE_WTSEM   (tstate_t)5

On a semaphore.

Definition at line 72 of file chschd.h.

Referenced by chMtxLockS(), chSchGoSleepS(), chSemSignalWait(), chSemWaitS(), and chSemWaitTimeoutS().

#define CH_STATE_WTMTX   (tstate_t)6

On a mutex.

Definition at line 73 of file chschd.h.

Referenced by chMtxLockS().

#define CH_STATE_WTCOND   (tstate_t)7

On a cond.variable.

Definition at line 74 of file chschd.h.

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

#define CH_STATE_SLEEPING   (tstate_t)8

Sleeping.

Definition at line 75 of file chschd.h.

Referenced by chThdSleepS().

#define CH_STATE_WTEXIT   (tstate_t)9

Waiting a thread.

Definition at line 76 of file chschd.h.

Referenced by chThdWait().

#define CH_STATE_WTOREVT   (tstate_t)10

One event.

Definition at line 77 of file chschd.h.

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

#define CH_STATE_WTANDEVT   (tstate_t)11

Several events.

Definition at line 78 of file chschd.h.

Referenced by chEvtSignalI(), chEvtWaitAll(), and chEvtWaitAllTimeout().

#define CH_STATE_SNDMSGQ   (tstate_t)12

Sending a message, in queue.

Definition at line 79 of file chschd.h.

Referenced by chMsgSend(), and chMtxLockS().

#define CH_STATE_SNDMSG   (tstate_t)13

Sent a message, waiting answer.

Definition at line 82 of file chschd.h.

Referenced by chMsgGet(), chMsgRelease(), and chMsgWait().

#define CH_STATE_WTMSG   (tstate_t)14

Waiting for a message.

Definition at line 85 of file chschd.h.

Referenced by chMsgSend(), and chMsgWait().

#define CH_STATE_FINAL   (tstate_t)15

Thread terminated.

Definition at line 88 of file chschd.h.

Referenced by chSchReadyAheadI(), chSchReadyI(), chThdExitS(), chThdRelease(), chThdTerminatedX(), and chThdWait().

#define CH_STATE_NAMES
Value:
"READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", \
"WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", \
"SNDMSG", "WTMSG", "FINAL"

Thread states as array of strings.

Each element in an array initialized with this macro can be indexed using the numeric thread state values.

Definition at line 95 of file chschd.h.

#define CH_FLAG_MODE_MASK   (tmode_t)3U

Thread memory mode mask.

Definition at line 105 of file chschd.h.

Referenced by chThdExitS(), and chThdRelease().

#define CH_FLAG_MODE_STATIC   (tmode_t)0U

Static thread.

Definition at line 108 of file chschd.h.

Referenced by _thread_init(), and chThdExitS().

#define CH_FLAG_MODE_HEAP   (tmode_t)1U

Thread allocated from a Memory Heap.

Definition at line 109 of file chschd.h.

Referenced by chThdCreateFromHeap(), and chThdRelease().

#define CH_FLAG_MODE_MPOOL   (tmode_t)2U

Thread allocated from a Memory Pool.

Definition at line 112 of file chschd.h.

Referenced by chThdCreateFromMemoryPool(), and chThdRelease().

#define CH_FLAG_TERMINATE   (tmode_t)4U

Termination requested flag.

Definition at line 115 of file chschd.h.

Referenced by chThdShouldTerminateX(), and chThdTerminate().

#define firstprio (   rlp)    ((rlp)->next->prio)

Returns the priority of the first thread on the given ready list.

Function Class:
Not an API, this function is for internal use only.

Definition at line 452 of file chschd.h.

Referenced by chSchDoYieldS(), chSchIsPreemptionRequired(), chSchIsRescRequiredI(), and queue_notempty().

#define __CH_STRINGIFY (   a)    #a

Utility to make the parameter a quoted string.

Definition at line 110 of file chsystypes.h.

Typedef Documentation

typedef struct ch_thread thread_t

Type of a thread structure.

Definition at line 52 of file chsystypes.h.

Type of a thread reference.

Definition at line 57 of file chsystypes.h.

Type of a generic threads single link list, it works like a stack.

Definition at line 62 of file chsystypes.h.

Type of a generic threads bidirectional linked list header and element.

Definition at line 69 of file chsystypes.h.

typedef struct ch_ready_list ready_list_t

Type of a ready list header.

Definition at line 76 of file chsystypes.h.

typedef void(* vtfunc_t) (void *p)

Type of a Virtual Timer callback function.

Definition at line 81 of file chsystypes.h.

Type of a Virtual Timer structure.

Definition at line 86 of file chsystypes.h.

Type of virtual timers list header.

Definition at line 91 of file chsystypes.h.

Type of a system debug structure.

Definition at line 96 of file chsystypes.h.

typedef struct ch_system ch_system_t

Type of system data structure.

Definition at line 101 of file chsystypes.h.

Function Documentation

void _scheduler_init ( void  )

Scheduler initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 65 of file chschd.c.

References NOPRIO, queue_init(), and ch_system::rlist.

Referenced by chSysInit().

Here is the call graph for this function:

static void queue_prio_insert ( thread_t tp,
threads_queue_t tqp 
)
inline

Inserts a thread into a priority ordered queue.

Note
The insertion is done by scanning the list from the highest priority toward the lowest.
Parameters
[in]tpthe pointer to the thread to be inserted in the list
[in]tqpthe pointer to the threads list header
Function Class:
Not an API, this function is for internal use only.

Definition at line 86 of file chschd.c.

References ch_threads_queue::next, ch_threads_queue::prev, ch_thread::prio, and ch_thread::queue.

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

static void queue_insert ( thread_t tp,
threads_queue_t tqp 
)
inline

Inserts a thread into a queue.

Parameters
[in]tpthe pointer to the thread to be inserted in the list
[in]tqpthe pointer to the threads list header
Function Class:
Not an API, this function is for internal use only.

Definition at line 106 of file chschd.c.

References ch_threads_queue::next, ch_threads_queue::prev, and ch_thread::queue.

Referenced by chThdEnqueueTimeoutS(), and queue_notempty().

static thread_t * queue_fifo_remove ( threads_queue_t tqp)
inline

Removes the first-out thread from a queue and returns it.

Note
If the queue is priority ordered then this function returns the thread with the highest priority.
Parameters
[in]tqpthe pointer to the threads list header
Returns
The removed thread pointer.
Function Class:
Not an API, this function is for internal use only.

Definition at line 124 of file chschd.c.

References ch_threads_queue::next, ch_threads_queue::prev, and ch_thread::queue.

Referenced by chCondBroadcastI(), chCondSignal(), chCondSignalI(), chMsgWait(), chMtxUnlock(), chMtxUnlockAll(), chMtxUnlockAllS(), chMtxUnlockS(), chSchDoReschedule(), chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), chSchGoSleepS(), chSemAddCounterI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chThdDoDequeueNextI(), and queue_notempty().

static thread_t * queue_lifo_remove ( threads_queue_t tqp)
inline

Removes the last-out thread from a queue and returns it.

Note
If the queue is priority ordered then this function returns the thread with the lowest priority.
Parameters
[in]tqpthe pointer to the threads list header
Returns
The removed thread pointer.
Function Class:
Not an API, this function is for internal use only.

Definition at line 143 of file chschd.c.

References ch_threads_queue::next, ch_threads_queue::prev, and ch_thread::queue.

Referenced by chSemResetI(), and queue_notempty().

static thread_t * queue_dequeue ( thread_t tp)
inline

Removes a thread from a queue and returns it.

The thread is removed from the queue regardless of its relative position and regardless the used insertion method.

Parameters
[in]tpthe pointer to the thread to be removed from the queue
Returns
The removed thread pointer.
Function Class:
Not an API, this function is for internal use only.

Definition at line 162 of file chschd.c.

References ch_threads_queue::next, ch_threads_queue::prev, and ch_thread::queue.

Referenced by chMtxLockS(), chSchGoSleepS(), and queue_notempty().

static void list_insert ( thread_t tp,
threads_list_t tlp 
)
inline

Pushes a thread_t on top of a stack list.

Parameters
[in]tpthe pointer to the thread to be inserted in the list
[in]tlpthe pointer to the threads list header
Function Class:
Not an API, this function is for internal use only.

Definition at line 178 of file chschd.c.

References ch_threads_list::next, ch_threads_queue::next, and ch_thread::queue.

Referenced by chThdWait(), and queue_isempty().

static thread_t * list_remove ( threads_list_t tlp)
inline

Pops a thread from the top of a stack list and returns it.

Precondition
The list must be non-empty before calling this function.
Parameters
[in]tlpthe pointer to the threads list header
Returns
The removed thread pointer.
Function Class:
Not an API, this function is for internal use only.

Definition at line 193 of file chschd.c.

References ch_threads_list::next, ch_threads_queue::next, and ch_thread::queue.

Referenced by chThdExitS().

thread_t * chSchReadyI ( thread_t tp)

Inserts a thread in the Ready List placing it behind its peers.

The thread is positioned behind all threads with higher or equal priority.

Precondition
The thread must not be already inserted in any list through its next and prev or list corruption would occur.
Postcondition
This function does not reschedule so a call to a rescheduling function must be performed before unlocking the kernel. Note that interrupt handlers always reschedule on exit so an explicit reschedule must not be performed in ISRs.
Parameters
[in]tpthe thread to be made ready
Returns
The thread pointer.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 218 of file chschd.c.

References CH_STATE_FINAL, CH_STATE_READY, chDbgAssert, chDbgCheck, chDbgCheckClassI(), ch_threads_queue::next, ch_thread::queue, ch_system::rlist, and ch_thread::state.

Referenced by chCondBroadcastI(), chCondSignalI(), chEvtSignalI(), chMsgSend(), chMtxLockS(), chMtxUnlock(), chMtxUnlockAll(), chMtxUnlockAllS(), chMtxUnlockS(), chSchDoReschedule(), chSchDoRescheduleBehind(), chSchGoSleepS(), chSchWakeupS(), chSemAddCounterI(), chSemResetI(), chSemSignalI(), chSemSignalWait(), chThdCreateI(), chThdDoDequeueNextI(), chThdExitS(), chThdResumeI(), and chThdStartI().

Here is the call graph for this function:

thread_t * chSchReadyAheadI ( thread_t tp)

Inserts a thread in the Ready List placing it ahead its peers.

The thread is positioned ahead all threads with higher or equal priority.

Precondition
The thread must not be already inserted in any list through its next and prev or list corruption would occur.
Postcondition
This function does not reschedule so a call to a rescheduling function must be performed before unlocking the kernel. Note that interrupt handlers always reschedule on exit so an explicit reschedule must not be performed in ISRs.
Parameters
[in]tpthe thread to be made ready
Returns
The thread pointer.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 257 of file chschd.c.

References CH_STATE_FINAL, CH_STATE_READY, chDbgAssert, chDbgCheck, chDbgCheckClassI(), ch_threads_queue::next, ch_thread::queue, ch_system::rlist, and ch_thread::state.

Referenced by chSchDoReschedule(), and chSchDoRescheduleAhead().

Here is the call graph for this function:

void chSchGoSleepS ( tstate_t  newstate)

Puts the current thread to sleep into the specified state.

The thread goes into a sleeping state. The possible Thread States are defined into threads.h.

Parameters
[in]newstatethe new thread state
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 289 of file chschd.c.

References CH_CFG_IDLE_ENTER_HOOK, CH_CFG_TIME_QUANTUM, CH_STATE_CURRENT, CH_STATE_QUEUED, CH_STATE_READY, CH_STATE_SUSPENDED, CH_STATE_WTCOND, CH_STATE_WTSEM, chDbgCheckClassS(), chSchReadyI(), chSemFastSignalI(), chSysLockFromISR(), chSysSwitch, chSysUnlockFromISR(), currp, IDLEPRIO, MSG_TIMEOUT, queue_dequeue(), queue_fifo_remove(), ch_thread::rdymsg, ch_system::rlist, ch_thread::state, ch_thread::ticks, ch_thread::u, ch_thread::wtsemp, and ch_thread::wttrp.

Referenced by chCondWaitS(), chEvtWaitAll(), chEvtWaitAny(), chEvtWaitOne(), chMsgSend(), chMsgWait(), chMtxLockS(), chSchGoSleepTimeoutS(), chSemSignalWait(), chSemWaitS(), chThdExitS(), chThdSuspendS(), and chThdWait().

Here is the call graph for this function:

msg_t chSchGoSleepTimeoutS ( tstate_t  newstate,
sysinterval_t  timeout 
)

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 MSG_TIMEOUT low level message. The possible Thread States are defined into threads.h.

Parameters
[in]newstatethe new thread state
[in]timeoutthe number of ticks before the operation timeouts, the special values are handled as follow:
  • TIME_INFINITE the thread enters an infinite sleep state, this is equivalent to invoking chSchGoSleepS() but, of course, less efficient.
  • TIME_IMMEDIATE this value is not allowed.
Returns
The wakeup message.
Return values
MSG_TIMEOUTif a timeout occurs.
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 375 of file chschd.c.

References chDbgCheckClassS(), chSchGoSleepS(), chVTDoResetI(), chVTDoSetI(), chVTIsArmedI(), currp, and TIME_INFINITE.

Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chSemWaitTimeoutS(), chThdEnqueueTimeoutS(), chThdSleepS(), and chThdSuspendTimeoutS().

Here is the call graph for this function:

void chSchWakeupS ( thread_t ntp,
msg_t  msg 
)

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.

Precondition
The thread must not be already inserted in any list through its next and prev or list corruption would occur.
Note
It is equivalent to a chSchReadyI() followed by a chSchRescheduleS() but much more efficient.
The function assumes that the current thread has the highest priority.
Parameters
[in]ntpthe thread to be made ready
[in]msgthe wakeup message
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 412 of file chschd.c.

References CH_CFG_IDLE_LEAVE_HOOK, CH_STATE_CURRENT, chDbgAssert, chDbgCheckClassS(), chSchReadyI(), chSysSwitch, currp, IDLEPRIO, ch_thread::prio, ch_thread::rdymsg, ch_system::rlist, ch_thread::state, and ch_thread::u.

Referenced by chCondSignal(), chMsgReleaseS(), chSemSignal(), chThdCreate(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdResumeS(), and chThdStart().

Here is the call graph for this function:

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.

Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 456 of file chschd.c.

References chDbgCheckClassS(), chSchDoRescheduleAhead(), and chSchIsRescRequiredI().

Referenced by chBSemSignal(), chCondBroadcast(), chEvtBroadcastFlags(), chEvtSignal(), chGuardedPoolFree(), chGuardedPoolFreeS(), chMBFetchTimeoutS(), chMBPostAheadTimeoutS(), chMBPostTimeoutS(), chMBReset(), chMtxUnlock(), chMtxUnlockAll(), chSemReset(), chSemSignalWait(), chSysRestoreStatusX(), and chThdSetPriority().

Here is the call graph for this function:

bool chSchIsPreemptionRequired ( void  )

Evaluates if preemption is required.

The decision is taken by comparing the relative priorities and depending on the state of the round robin timeout counter.

Note
Not a user function, it is meant to be invoked by the scheduler itself or from within the port layer.
Return values
trueif there is a thread that must go in running state immediately.
falseif preemption is not required.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 479 of file chschd.c.

References currp, firstprio, and ch_system::rlist.

void chSchDoRescheduleBehind ( void  )

Switches to the first thread on the runnable queue.

The current thread is positioned in the ready list behind all threads having the same priority. The thread regains its time quantum.

Note
Not a user function, it is meant to be invoked by the scheduler itself.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 507 of file chschd.c.

References CH_CFG_IDLE_LEAVE_HOOK, CH_CFG_TIME_QUANTUM, CH_STATE_CURRENT, chSchReadyI(), chSysSwitch, currp, IDLEPRIO, ch_thread::prio, queue_fifo_remove(), ch_system::rlist, and ch_thread::ticks.

Referenced by chSchCanYieldS(), and chSchPreemption().

Here is the call graph for this function:

void chSchDoRescheduleAhead ( void  )

Switches to the first thread on the runnable queue.

The current thread is positioned in the ready list ahead of all threads having the same priority.

Note
Not a user function, it is meant to be invoked by the scheduler itself.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 540 of file chschd.c.

References CH_CFG_IDLE_LEAVE_HOOK, CH_STATE_CURRENT, chSchReadyAheadI(), chSysSwitch, currp, IDLEPRIO, ch_thread::prio, queue_fifo_remove(), and ch_system::rlist.

Referenced by chSchDoYieldS(), chSchPreemption(), and chSchRescheduleS().

Here is the call graph for this function:

void chSchDoReschedule ( void  )

Switches to the first thread on the runnable queue.

The current thread is positioned in the ready list behind or ahead of all threads having the same priority depending on if it used its whole time slice.

Note
Not a user function, it is meant to be invoked by the scheduler itself or from within the port layer.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 570 of file chschd.c.

References CH_CFG_IDLE_LEAVE_HOOK, CH_CFG_TIME_QUANTUM, CH_STATE_CURRENT, chSchReadyAheadI(), chSchReadyI(), chSysSwitch, currp, IDLEPRIO, ch_thread::prio, queue_fifo_remove(), ch_system::rlist, and ch_thread::ticks.

Here is the call graph for this function:

static void list_init ( threads_list_t tlp)
inlinestatic

Threads list initialization.

Parameters
[in]tlppointer to the threads list object
Function Class:
Not an API, this function is for internal use only.

Definition at line 510 of file chschd.h.

References ch_threads_list::next.

Referenced by _thread_init().

static bool list_isempty ( threads_list_t tlp)
inlinestatic

Evaluates to true if the specified threads list is empty.

Parameters
[in]tlppointer to the threads list object
Returns
The status of the list.
Function Class:
Not an API, this function is for internal use only.

Definition at line 523 of file chschd.h.

References ch_threads_list::next.

static bool list_notempty ( threads_list_t tlp)
inlinestatic

Evaluates to true if the specified threads list is not empty.

Parameters
[in]tlppointer to the threads list object
Returns
The status of the list.
Function Class:
Not an API, this function is for internal use only.

Definition at line 536 of file chschd.h.

References ch_threads_queue::next, and ch_threads_queue::prev.

Referenced by chThdExitS().

static void queue_init ( threads_queue_t tqp)
inlinestatic

Threads queue initialization.

Parameters
[in]tqppointer to the threads queue object
Function Class:
Not an API, this function is for internal use only.

Definition at line 548 of file chschd.h.

References ch_threads_queue::next.

Referenced by _scheduler_init(), _thread_init(), chCondObjectInit(), chMtxObjectInit(), chSemObjectInit(), and chThdQueueObjectInit().

static bool queue_isempty ( const threads_queue_t tqp)
inlinestatic

Evaluates to true if the specified threads queue is empty.

Parameters
[in]tqppointer to the threads queue object
Returns
The status of the queue.
Function Class:
Not an API, this function is for internal use only.

Definition at line 562 of file chschd.h.

References list_insert(), ch_threads_list::next, ch_threads_queue::next, and ch_thread::queue.

Referenced by chSemAddCounterI(), chSemResetI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), and chThdQueueIsEmptyI().

Here is the call graph for this function:

static bool queue_notempty ( const threads_queue_t tqp)
inlinestatic

Evaluates to true if the specified threads queue is not empty.

Parameters
[in]tqppointer to the threads queue object
Returns
The status of the queue.
Function Class:
Not an API, this function is for internal use only.

Definition at line 575 of file chschd.h.

References chDbgCheckClassI(), chSchIsRescRequiredI(), currp, firstprio, ch_threads_list::next, ch_threads_queue::next, ch_threads_queue::prev, ch_thread::prio, ch_thread::queue, queue_dequeue(), queue_fifo_remove(), queue_insert(), queue_lifo_remove(), queue_prio_insert(), and ch_system::rlist.

Referenced by chCondBroadcastI(), chCondSignal(), chCondSignalI(), chMtxQueueNotEmptyS(), chSemAddCounterI(), chSemResetI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdDequeueAllI(), chThdDequeueNextI(), and chThdDoDequeueNextI().

Here is the call graph for this function:

static bool chSchIsRescRequiredI ( void  )
inlinestatic

Determines if the current thread must reschedule.

This function returns true if there is a ready thread with higher priority.

Returns
The priorities situation.
Return values
falseif rescheduling is not necessary.
trueif there is a ready thread at higher priority.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 655 of file chschd.h.

References chDbgCheckClassS(), currp, firstprio, and ch_system::rlist.

Referenced by chSchRescheduleS(), and queue_notempty().

Here is the call graph for this function:

static bool chSchCanYieldS ( void  )
inlinestatic

Determines if yielding is possible.

This function returns true if there is a ready thread with equal or higher priority.

Returns
The priorities situation.
Return values
falseif yielding is not possible.
trueif there is a ready thread at equal or higher priority.
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 673 of file chschd.h.

References chDbgCheckClassS(), and chSchDoRescheduleBehind().

Here is the call graph for this function:

static void chSchDoYieldS ( void  )
inlinestatic

Yields the time slot.

Yields the CPU control to the next thread in the ready list with equal or higher priority, if any.

Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 687 of file chschd.h.

References chSchDoRescheduleAhead(), currp, firstprio, and ch_system::rlist.

Referenced by chThdYield().

Here is the call graph for this function:

static void chSchPreemption ( void  )
inlinestatic

Inline-able preemption code.

This is the common preemption code, this function must be invoked exclusively from the port layer.

Function Class:
Special function, this function has special requirements see the notes.

Definition at line 703 of file chschd.h.

References chSchDoRescheduleAhead(), and chSchDoRescheduleBehind().

Here is the call graph for this function:

Variable Documentation