Main Page   Compound List   File List   Compound Members   File Members  

Semaphore Class Reference

#include <synch.h>

List of all members.

Public Methods

 Semaphore (char *debugName, int initialValue)
 ~Semaphore ()
char * getName ()
void P ()
void V ()

Private Attributes

char * name
int value
Listqueue


Constructor & Destructor Documentation

Semaphore::Semaphore char *    debugName,
int    initialValue
 

Definition at line 36 of file synch.cc.

References name, queue, and value.

00037 {
00038     name = debugName;
00039     value = initialValue;
00040     queue = new List;
00041 }

Semaphore::~Semaphore  
 

Definition at line 49 of file synch.cc.

References queue.

00050 {
00051     delete queue;
00052 }


Member Function Documentation

char* Semaphore::getName   [inline]
 

Definition at line 43 of file synch.h.

References name.

00043 { return name;}                 // debugging assist

void Semaphore::P  
 

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 }

void Semaphore::V  
 

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 }


Member Data Documentation

char* Semaphore::name [private]
 

Definition at line 49 of file synch.h.

Referenced by getName, and Semaphore.

List* Semaphore::queue [private]
 

Definition at line 51 of file synch.h.

Referenced by P, Semaphore, V, and ~Semaphore.

int Semaphore::value [private]
 

Definition at line 50 of file synch.h.

Referenced by P, Semaphore, and V.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:58 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees