Class Guard
Placement in the overall structure
- Module
- guard
- Base classes
- Locker
- Derived classes
- None
- Time of creation
- Task 3
- Files
guard.h guard.cc
Description
The Guard class is used for synchronization between "normal" kernel activities (currently outputs, later system calls) and interrupt handling routines. For this purpose Guard has a queue (a Queue object) into which Gate objects can be enqueued. This is always necessary if the critical section is occupied at the time an interrupt occurs, so theepilogue()
method may not be
processed immediately. The accumulated epilogues are handled as soon as
the critical section is released again.
Public methods
void leave ()
- Regular control flow leaves the critical section. Accumulated epilogues can be processed now.
void relay (Gate* item)
- This method is called by
guardian ()
if the previously executed prologue has indicated by a return value oftrue
that its epilogue should be executed. Whether the epilogue is handled immediately or only added to the epilogue queue depends on whether the critical section is free or occupied.
Notes
- The epilogue queue represents a central data structure whose consistency must be appropriately ensured.
- Since Gate objects have only a single chain pointer, they must only be enqueued once in the epilogue queue at any given time. Consequently, if two interrupts of the same kind follow each other so quickly that the associated epilogue has not yet been handled, it is not allowed to add the same Gate object to the epilogue queue twice. The Gate class provides methods to record or check this.
- An operating system should always disable interrupts for as short as possible. Therefore, the pro/epilogue model allows for epilogues to be interrupted by prologues. For OOStuBS this means that interrupts should already be enabled before the epilogue of an interrupt handler is executed.