#include <synch.h>
Public Methods | |
| Semaphore (char *debugName, int initialValue) | |
| set initial value. More... | |
| ~Semaphore () | |
| de-allocate semaphore. More... | |
| char* | getName () |
| debugging assist. More... | |
| void | P () |
| these are the only operations on a semaphore. More... | |
| void | V () |
| they are both *atomic*. More... | |
| void | SelfTest () |
| test routine for semaphore implementation. More... | |
Private Attributes | |
| char* | name |
| useful for debugging. More... | |
| int | value |
| semaphore value, always >= 0. More... | |
| List<Thread *>* | queue |
| threads waiting in P() for the value to be > 0. More... | |
Definition at line 40 of file synch.h.
|
|
set initial value. Semaphore::Semaphore Initialize a semaphore, so that it can be used for synchronization. "debugName" is an arbitrary name, useful for debugging. "initialValue" is the initial value of the semaphore. Definition at line 47 of file synch.cc. Referenced by SelfTest().
|
|
|
de-allocate semaphore. Semaphore::Semaphore De-allocate semaphore, when no longer needed. Assume no one is still waiting on the semaphore! |
|
|
these are the only operations on a semaphore. Semaphore::P Wait until semaphore value > 0, then decrement. Checking the value and decrementing must be done atomically, so we need to disable interrupts before checking the value. Note that Thread::Sleep assumes that interrupts are disabled when it is called. Definition at line 76 of file synch.cc. Referenced by Lock::Acquire(), SynchConsoleInput::GetChar(), PostOfficeInput::PostalDelivery(), SynchConsoleOutput::PutChar(), SynchDisk::ReadSector(), SelfTest(), SelfTestHelper(), PostOfficeOutput::Send(), Condition::Wait(), ElevatorInspector::WaitForNextControllerEvent(), ElevatorInspector::WaitForNextRiderEvent(), and SynchDisk::WriteSector().
|
|
|
test routine for semaphore implementation.
Definition at line 136 of file synch.cc. Referenced by ThreadedKernel::SelfTest().
|
|
|
they are both *atomic*. Semaphore::V Increment semaphore value, waking up a waiter if necessary. As with P(), this operation must be atomic, so we need to disable interrupts. Scheduler::ReadyToRun() assumes that interrupts are disabled when it is called. Definition at line 103 of file synch.cc. Referenced by SynchDisk::CallBack(), SynchConsoleOutput::CallBack(), SynchConsoleInput::CallBack(), PostOfficeOutput::CallBack(), PostOfficeInput::CallBack(), ElevatorInspector::CallBack(), Lock::Release(), SelfTest(), SelfTestHelper(), and Condition::Signal().
|
|
|
debugging assist.
|
|
|
useful for debugging.
|
|
|
threads waiting in P() for the value to be > 0.
|
|
|
semaphore value, always >= 0.
|
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001