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

PLearn::ResourceSemaphore Class Reference

#include <Semaphores.h>

Collaboration diagram for PLearn::ResourceSemaphore:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ResourceSemaphore (int nb_semaphores=1)
 construct given number of semaphores for controlling so many exclusive resources.

 ResourceSemaphore (SemId semid)
 access an existing semaphore

void lock (int resource=0)
void unlock (int resource=0)
 Release a lock on a resource.

bool locked (int resource=0)
 to check without waiting wether a resource is locked.

void clearAnyLock ()
 make sure we are back in unlocked mode: clear locks of all resources

void clearAnyLock (int resource)
 make sure we are back in unlocked mode: clear lock for given resource

 ~ResourceSemaphore ()
 release the semaphore upon destruction of object


Protected Attributes

SemId id
 semaphore id provided by the operating system at construction

bool owner
 true if this process is the owner of the semaphore, i.e

int n_semaphores
 there can be several semaphores in the same object


Constructor & Destructor Documentation

PLearn::ResourceSemaphore::ResourceSemaphore int  nb_semaphores = 1  ) 
 

construct given number of semaphores for controlling so many exclusive resources.

Definition at line 49 of file Semaphores.cc.

References clearAnyLock(), PLearn::endl(), n_semaphores, and PLERROR.

PLearn::ResourceSemaphore::ResourceSemaphore SemId  semid  ) 
 

access an existing semaphore

Definition at line 62 of file Semaphores.cc.

References n_semaphores, and PLERROR.

PLearn::ResourceSemaphore::~ResourceSemaphore  ) 
 

release the semaphore upon destruction of object

Definition at line 124 of file Semaphores.cc.

References PLearn::endl(), owner, PLERROR, and PLearn::semun::val.


Member Function Documentation

void PLearn::ResourceSemaphore::clearAnyLock int  resource  ) 
 

make sure we are back in unlocked mode: clear lock for given resource

Definition at line 114 of file Semaphores.cc.

References PLERROR, and PLearn::semun::val.

void PLearn::ResourceSemaphore::clearAnyLock  ) 
 

make sure we are back in unlocked mode: clear locks of all resources

Definition at line 108 of file Semaphores.cc.

References n_semaphores.

Referenced by ResourceSemaphore().

void PLearn::ResourceSemaphore::lock int  resource = 0  ) 
 

Wait for a resource to be freed and then take control of it. This is done by waiting for the resource semaphore's to become 1 and then decrementing its value to 0 (thus taking the lock).

Definition at line 74 of file Semaphores.cc.

References PLERROR.

bool PLearn::ResourceSemaphore::locked int  resource = 0  ) 
 

to check without waiting wether a resource is locked.

Definition at line 101 of file Semaphores.cc.

References PLearn::semun::val.

Referenced by unlock().

void PLearn::ResourceSemaphore::unlock int  resource = 0  ) 
 

Release a lock on a resource.

This is done by incrementing the resource's semaphore. No waiting.

Definition at line 86 of file Semaphores.cc.

References locked(), and PLERROR.


Member Data Documentation

SemId PLearn::ResourceSemaphore::id [protected]
 

semaphore id provided by the operating system at construction

Definition at line 96 of file Semaphores.h.

int PLearn::ResourceSemaphore::n_semaphores [protected]
 

there can be several semaphores in the same object

Definition at line 99 of file Semaphores.h.

Referenced by clearAnyLock(), and ResourceSemaphore().

bool PLearn::ResourceSemaphore::owner [protected]
 

true if this process is the owner of the semaphore, i.e

the semaphore will be released with this object is deleted

Definition at line 97 of file Semaphores.h.

Referenced by ~ResourceSemaphore().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:24:35 2004 for PLearn by doxygen 1.3.7