
106 Chapter 8: Operating Systems
to make such a guarantee is to disable interrupts for the duration of the critical
section. So enterCS is called at the beginning of the critical section to save the
interrupt enable state and disable further interrupts. And exitCS is called at the end
to restore the previously saved interrupt state. We will see this same technique
used in each of the routines that follow.
There are several other routines that I’ve called from the constructor in the previ-
ous code, but I don’t have the space to list here. These are the routines contextInit
and os.readyList.insert. The contextInit routine establishes the initial context for a
task. This routine is necessarily processor-specific and, therefore, written in assem-
bly language.
contextInit has four parameters. The first is a pointer to the context data structure
that is to be initialized. The second is a pointer to the startup function. This is a
special ADEOS function, called run, that is used to start a task and clean up
behind it if the associated function later exits. The third parameter is a pointer to
the new Task object. This parameter is passed to run so the function associated
with the task can be started. The fourth and final parameter is a pointer to the new
task’s stack.
The other function call is to os.readyList.insert. This call adds the new task to the
operating system’s internal list of ready tasks. ...