Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Tasks are added to the ready list by a number of µC/OS-III services. The most obvious service is OSTaskCreate(), which always creates a task in the ready-to-run state and adds the task to the ready list. As shown in Figure 6-6, we created a task, and specified a priority level where tasks already existed (two in this example) in the ready list at the desired priority level. OSTaskCreate() will then insert the new task at the end of the list of tasks at that priority level.

Anchor
Figure - Inserting a newly created task in the ready list
Figure - Inserting a newly created task in the ready list

Panel
borderWidth0
titleFigure - Inserting a newly created task in the ready list

Image Added


Panel
bgColor#f0f0f0

(1) Before calling OSTaskCreate() (in this example), two tasks were in the ready list at priority “prio”.

(2) A new TCB is passed to OSTaskCreate() and, µC/OS-III initialized the contents of that TCB.

(3) OSTaskCreate() calls OS_RdyListInsertTail(), which links the new TCB to the ready list by setting up four pointers and also incrementing the .Entries field of OSRdyList[prio]. Not shown in Figure 6-6 is that OSTaskCreate() also calls OS_PrioInsert() to set the bit in the bitmap table. Of course, this operation is not necessary as there are already entries in the list at this priority. However, OS_PrioInsert() is a very fast call and thus it should not affect performance.

The reason the new TCB is added to the end of the list is that the current head of the list could be the task creator and it could be at the same priority. So, there is no reason to make the new task the next task to run. In fact, a task being made ready will be inserted at the tail of the list if the current task is at the same priority. However, if a task is being made ready at a different priority than the current task, it will be inserted at the head of the list.