Pend Lists

A task is placed in a Pend List (also called a Wait List) when it is waiting on a semaphore to be signaled, a mutual exclusion semaphore to be released, an event flag group to be posted, or a message queue to be posted.

See …For…Kernel Object
Resource ManagementSemaphores
Mutual Exclusion
Semaphores
OS_SEM
OS_MUTEX
SynchronizationSemaphores
Event Flags
OS_SEM
OS_FLAG_GRP
Message PassingMessage QueuesOS_Q

A pend list is similar to the Ready List, except that instead of keeping track of tasks that are ready-to-run, the pend list keeps track of tasks waiting for an object to be posted. In addition, the pend list is sorted by priority; the highest priority task waiting on the object is placed at the head of the list, and the lowest priority task waiting on the object is placed at the end of the list.

A pend list is a data structure of type OS_PEND_LIST, which consists of three fields as shown in the figure below.

Figure - Pend List


.NbrEntries

Contains the current number of entries in the pend list. Each entry in the pend list points to a task that is waiting for the kernel object to be posted.

.TailPtr

Is a pointer to the last task in the list (i.e., the lowest priority task).

.HeadPtr

Is a pointer to the first task in the list (i.e., the highest priority task).

The figure below indicates that each kernel object using a pend list contains the same three fields at the beginning of the kernel object that we called an OS_PEND_OBJ. Notice that the first field is always a “Type” which allows µC/OS-III to know if the kernel object is a semaphore, a mutual exclusion semaphore, an event flag group, or a message queue object.

Figure - OS_PEND_OBJ at the beginning of certain kernel objects


The table below shows that the “Type” field of each of the above objects is initialized to contain four ASCII characters when the respective object is created. This allows the user to identify these objects when performing a memory dump using a debugger.

Table - Kernel objects with initialized “Type” field
Kernel ObjectType
Semaphore‘S’ ‘E’ ‘M’ ‘A’
Mutual Exclusion Semaphore‘M’ ‘U’ ‘T’ ‘X’
Event Flag Group‘F’ ‘L’ ‘A’ ‘G’
Message Queue‘Q’ ‘U’ ‘E’ ‘U’


A pend list is a doubly linked list of all the task OS_TCBs that are waiting on the kernel object. 

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

Table - Pend List access functions
FunctionDescription
OS_PendListChangePrio()Change the priority of a task in a pend list
OS_PendListInit()Initialize a pend list
OS_PendListInsertPrio()Insert a task in priority order in the pend list
OS_PendListRemove()Remove a task from a pend list