Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | List of all members
om::threads::Semaphore Class Reference

A class that implements a count-based synchronization object. More...

#include <omSemaphore.h>

Public Member Functions

 Semaphore ()
 Create a new semaphore object with an initial value of 0. More...
 
 Semaphore (Int initialValue)
 Create a new semaphore object with the specified initial value. More...
 
 Semaphore (const Semaphore &semaphore)
 Create a new semaphore with the same value as the specified semaphore. More...
 
 ~Semaphore ()
 Destroy a semaphore object. More...
 
Semaphoreoperator= (const Semaphore &semaphore)
 Assign one semaphore to another. More...
 
Bool up ()
 Increase the value of the semaphore by 1. More...
 
Bool down ()
 Decrease the value of the semaphore by 1. More...
 
Bool reset ()
 Awaken all threads that are waiting on the semaphore and set its value to 0. More...
 
Int getValue () const
 Return the current value of the semaphore. More...
 

Detailed Description

A class that implements a count-based synchronization object.

Constructor & Destructor Documentation

om::threads::Semaphore::Semaphore ( )

Create a new semaphore object with an initial value of 0.

om::threads::Semaphore::Semaphore ( Int  initialValue)

Create a new semaphore object with the specified initial value.

om::threads::Semaphore::Semaphore ( const Semaphore semaphore)

Create a new semaphore with the same value as the specified semaphore.

om::threads::Semaphore::~Semaphore ( )

Destroy a semaphore object.

This has the effect of awakening all waiting threads. This is done in order to prevent deadlocks in the case of accidental destruction.

Member Function Documentation

Semaphore& om::threads::Semaphore::operator= ( const Semaphore semaphore)

Assign one semaphore to another.

This awakens all threads currently waiting on the semaphore and gives the semaphore an initial value equal to the other semaphore's current value.

Bool om::threads::Semaphore::up ( )

Increase the value of the semaphore by 1.

This awakens at most 1 thread which was suspended after a call to down() when the value of the semaphore was 0. The awoken thread then decreases the value of the semaphore by 1 and returns from down(). Threads are awoken in a first-in-first-out order: the first thread to start waiting on a call to down is the first awoken after a call to up().

The method returns whether or not the operation was successful.

Bool om::threads::Semaphore::down ( )

Decrease the value of the semaphore by 1.

If the value of the semaphore before the call to down() was 0, then the calling thread is blocked until another thread makes a call to up().

The method returns whether or not the operation was successful.

Bool om::threads::Semaphore::reset ( )

Awaken all threads that are waiting on the semaphore and set its value to 0.

The method returns whether or not the operation was successful.

Int om::threads::Semaphore::getValue ( ) const

Return the current value of the semaphore.

The returned value is not sychronized with calls to up()/down() on other threads, so it may not represent the instantaneous state of the semaphore.


The documentation for this class was generated from the following file: