The implementation of semaphores in Xinu consists of the following:
Semaphore lists and wait state.
Semaphore Table
The routines wait, signal, create, and delete.
Semaphore Lists and Wait state
A process waiting on a semaphore is put into the wait state and
the semaphore list associated with the semaphore.
This list implements the queue associated with the semaphore.
Semaphore Table
The table contains an entry for each semaphore which in turn contains:
integer count of the semaphore
head and tail of list associated with the semaphore.
A semaphore is identified by the index of its semaphore table entry.
The Routine Wait
Decrements count of the semaphore.
If count is negative puts process in the wait state and the list
associated with the semaphore.
Also calls reschedule.
The Routine Signal
If count is negative puts process at head of semaphore list in ready list, and reschedules.
Increments the count of the semaphore (before calling reschedule)
The Routine Create
Takes as argument the initial count of the semaphore.
Return error if count is negative. (why?)
Create a table entry for the semaphore by finding an unused one and initializing it. Each table entry, at startup time, is associated with a semaphore list. So the latter does not have to be created.
Returns index of the semaphore.
The Routine Delete
Frees table entry.
Puts waiting processes in ready list.
Calls reschedule.