About the Ready List

Tasks that are ready-to-run are placed in the Ready List. As shown in the figure below, the ready list is an array (OSRdyList[]) containing OS_CFG_PRIO_MAX entries, with each entry defined by the data type OS_RDY_LIST (see os.h). An OS_RDY_LIST entry consists of three fields: .Entries, .TailPtr and .HeadPtr.

.Entries contains the number of ready-to-run tasks at the priority level corresponding to the entry in the ready list. .Entries is set to zero (0) if there are no tasks ready-to-run at a given priority level.

.TailPtr and .HeadPtr are used to create a doubly linked list of all the tasks that are ready at a specific priority. .HeadPtr points to the head of the list and .TailPtr points to its tail.

The “index” into the array is the priority level associated with a task. For example, if a task is created at priority level 5 then it will be inserted in the table at OSRdyList[5] if that task is ready-to-run.

The table below shows the functions that µC/OS-III uses to manipulate entries in the ready list. These functions are found in os_core.c and are internal to µC/OS-III so, the application code must never call them.

Table - Ready List access functions
FunctionDescription
OS_RdyListInit()Initialize the ready list to “empty” (see the figure below)
OS_RdyListInsert()Insert a TCB into the ready list
OS_RdyListInsertHead()Insert a TCB at the head of the list
OS_RdyListInsertTail()Insert a TCB at the tail of the list
OS_RdyListMoveHeadToTail()Move a TCB from the head to the tail of the list
OS_RdyListRemove()Remove a TCB from the ready list


Figure - Empty Ready List

Assuming all internal µC/OS-III’s tasks are enabled, the figure below shows the state of the ready list after calling OSInit() (i.e., µC/OS-III’s initialization). It is assumed that each µC/OS-III task had a unique priority. With µC/OS-III, this does not have to be the case.

(1) There is only one entry in OSRdyList[OS_CFG_PRIO_MAX-1], the idle task.

(2) The list points to OS_TCBs. Only relevant fields of the TCB are shown. The .PrevPtr and .NextPtr are used to form a doubly linked list of OS_TCBs associated to tasks at the same priority. For the idle task, these fields always point to NULL.

(3) The tick task and the other three optional tasks have their own priority level, as shown. Typically, you would set the priority of the tick task higher than the timer task and, the timer task higher in priority than the statistic task.

(4) Both the tail and head pointers point to the same TCB when there is only one TCB at a given priority level.

Figure - Ready List after calling OSInit()

(1) The tick task and the other three optional tasks have their own priority level, as shown. Typically, you would set the priority of the tick task higher than the timer task and, the timer task higher in priority than the statistic task.

(2) Both the tail and head pointers point to the same TCB when there is only one TCB at a given priority level.