Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Semaphore Class Reference

This class implements a standard semaphore. More...

#include <tsemaphore.h>

Collaboration diagram for Semaphore:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Semaphore (int initial_value=0)
 Set up a semaphore with passed initial value defaulting to 0:.

 ~Semaphore ()
int value ()
 Get the current value of the semaphore:.

void post ()
 Increase the semaphore counter:.

void wait ()
bool test ()

Private Attributes

ConditionMutex m
WaitCondition c
volatile int v
 volatile needed?


Detailed Description

This class implements a standard semaphore.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Semaphores are counters for resources shared between threads. The basic operations on semaphores are: increment the counter atomically, and wait until the counter is non-null and decrement it atomically.

Definition at line 51 of file tsemaphore.h.


Constructor & Destructor Documentation

Semaphore::Semaphore int  initial_value = 0  )  [inline]
 

Set up a semaphore with passed initial value defaulting to 0:.

Definition at line 64 of file tsemaphore.h.

References USE_PRIVATE__POSIX_SEMAPHORES.

Semaphore::~Semaphore  )  [inline]
 

Destroy a semaphore. Make sure no thread is waiting for it before destroying a semaphore.

Definition at line 73 of file tsemaphore.h.

References USE_PRIVATE__POSIX_SEMAPHORES.


Member Function Documentation

void Semaphore::post  ) 
 

Increase the semaphore counter:.

Definition at line 21 of file tsemaphore.cc.

References WaitCondition::broadcast(), c, ConditionMutex::lock(), m, ConditionMutex::unlock(), and v.

bool Semaphore::test  ) 
 

Non-blocking version. If the value of the semaphore is >0, decrease it and return 0. Otherwise return 1 instead of waiting.

Definition at line 52 of file tsemaphore.cc.

References ConditionMutex::lock(), m, ConditionMutex::unlock(), and v.

int Semaphore::value  )  [inline]
 

Get the current value of the semaphore:.

Definition at line 81 of file tsemaphore.h.

References USE_PRIVATE__POSIX_SEMAPHORES.

void Semaphore::wait  ) 
 

Wait for semaphore to become non-zero, then atomically decrease the semaphore count.

Definition at line 32 of file tsemaphore.cc.

References c, ConditionMutex::lock(), m, ConditionMutex::unlock(), v, and WaitCondition::wait().


Member Data Documentation

WaitCondition Semaphore::c [private]
 

Definition at line 58 of file tsemaphore.h.

Referenced by post(), and wait().

ConditionMutex Semaphore::m [private]
 

Definition at line 57 of file tsemaphore.h.

Referenced by post(), test(), and wait().

volatile int Semaphore::v [private]
 

volatile needed?

Definition at line 59 of file tsemaphore.h.

Referenced by post(), test(), and wait().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:38 2005 for Ray by doxygen 1.3.5