Main Page | Alphabetical List | Class List | File List | Class Members | File Members

Semaphore Class Reference

#include <synch.h>

List of all members.

Public Member Functions

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


Constructor & Destructor Documentation

Semaphore::Semaphore char *  debugName,
int  initialValue
 

Definition at line 36 of file synch.cc.

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

Semaphore::~Semaphore  ) 
 

Definition at line 49 of file synch.cc.

00050 { 00051 delete queue; 00052 }


Member Function Documentation

char* Semaphore::getName  )  [inline]
 

Definition at line 43 of file synch.h.

00043 { return name;} // debugging assist

void Semaphore::P  ) 
 

Definition at line 64 of file synch.cc.

References List::Append(), currentThread, DEBUG(), Thread::getName(), interrupt, IntOff, IntStatus, Interrupt::SetLevel(), and Thread::Suspend().

Referenced by Ping(), and Pong().

00065 { 00066 IntStatus oldLevel = interrupt->SetLevel(IntOff); // disable interrupts 00067 00068 while (value == 0) 00069 { // semaphore not available 00070 queue->Append((void *)currentThread); // so go to sleep 00071 DEBUG('t', "Suspendp %s\n", currentThread->getName()); 00072 currentThread->Suspend(); 00073 } 00074 value--; // semaphore available, 00075 // consume its value 00076 00077 (void) interrupt->SetLevel(oldLevel); // re-enable interrupts 00078 }

void Semaphore::V  ) 
 

Definition at line 88 of file synch.cc.

References DEBUG(), Thread::getName(), interrupt, IntOff, IntStatus, Scheduler::ReadyToRun(), List::Remove(), scheduler, and Interrupt::SetLevel().

Referenced by Ping(), and Pong().

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 { 00096 scheduler->ReadyToRun(thread); 00097 DEBUG('t', "Wakeup %s\n", thread->getName()); 00098 } 00099 value++; 00100 (void) interrupt->SetLevel(oldLevel); 00101 }


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 12:33:49 2004 for NachOS by doxygen 1.3.8