#include <synch.h>
Public Methods | |
| Semaphore (char *debugName, int initialValue) | |
| ~Semaphore () | |
| char * | getName () |
| void | P () |
| void | V () |
Private Attributes | |
| char * | name |
| int | value |
| List * | queue |
|
||||||||||||
|
Definition at line 36 of file synch.cc. References name, queue, and value.
|
|
|
Definition at line 49 of file synch.cc. References queue.
00050 {
00051 delete queue;
00052 }
|
|
|
Definition at line 43 of file synch.h. References name.
00043 { return name;} // debugging assist
|
|
|
Definition at line 65 of file synch.cc. References List::Append, IntOff, IntStatus, queue, and value. Referenced by ConsoleTest, PostOffice::PostalDelivery, SynchConsole::ReadLine, SynchDisk::ReadSector, PostOffice::Send, SynchConsole::WriteLine, and SynchDisk::WriteSector.
00066 {
00067 IntStatus oldLevel = interrupt->SetLevel(IntOff); // disable interrupts
00068
00069 while (value == 0) { // semaphore not available
00070 queue->Append((void *)currentThread); // so go to sleep
00071 currentThread->Sleep();
00072 }
00073 value--; // semaphore available,
00074 // consume its value
00075
00076 (void) interrupt->SetLevel(oldLevel); // re-enable interrupts
00077 }
|
|
|
Definition at line 88 of file synch.cc. References IntOff, IntStatus, NULL, queue, List::Remove, and value. Referenced by PostOffice::IncomingPacket, PostOffice::PacketSent, SynchConsole::ReadAvail, ReadAvail, SynchDisk::RequestDone, SynchConsole::WriteDone, and WriteDone.
00089 {
00090 Thread *thread;
00091 IntStatus oldLevel = interrupt->SetLevel(IntOff);
00092
00093 thread = (Thread *)queue->Remove();
00094 if (thread != NULL) // make thread ready, consuming the V immediately
00095 scheduler->ReadyToRun(thread);
00096 value++;
00097 (void) interrupt->SetLevel(oldLevel);
00098 }
|
|
|
|
|
|
Definition at line 51 of file synch.h. Referenced by P, Semaphore, V, and ~Semaphore. |
|
|
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002