Hardware Reference
In-Depth Information
To ensure the consistency of the kernel data structures, all semaphore system calls
are executed with cpu interrupts disabled. Note that semaphore queues are ordered
by decreasing absolute deadlines, so that, when more tasks are blocked, the first task
awakened will be the one with the earliest deadline.
/*-----------------------------------------------------------*/
/* wait -- waits for an event */
/*-----------------------------------------------------------*/
void
wait (sem s)
{
<disable cpu interrupts>
if (vsem[s].count > 0) vsem[s].count --;
else
save context();
vdes[pexe].state = WAIT;
insert(pexe, &vsem[s].qsem);
dispatch();
load context();
<enable cpu interrupts>
}
The signal primitive is used by a task to signal an event associated with a semaphore.
If no tasks are blocked on that semaphore (that is, if the semaphore queue is empty),
the counter is incremented, and the task continues its execution. If there are blocked
tasks, the task with the earliest deadline is extracted from the semaphore queue and
is inserted in the ready queue. Since a task has been awakened, a context switch
may occur; hence, the context of the running task is saved, a task is selected by the
scheduler and a new context is loaded.
Search WWH ::




Custom Search