OpenGL Vizserver Reference Page


NAME
vsSemaphore - A counting semaphore

HEADER FILE
#include <vizserver/vsLock.h>

PUBLIC METHOD SUMMARY

   Creation and destruction
vsSemaphore ( int value=1);
vsSemaphore ( const vsSemaphore& copy);
~vsSemaphore (  );

   Usage
vsBool wait (  );
vsBool trywait (  );
vsBool post (  );

   Queries
int getValue (  );

CLASS DESCRIPTION
The vsSemaphore implements a counting semaphore that is compatible with vsThread.

Limitations
There may be system imposed limits on the number of semaphores allocable to a process (so don't use them with abandon).

METHOD DESCRIPTIONS

   vsSemaphore()
vsSemaphore ( int value=1);

Initializes this instance of vsSemaphore with the counter set to value.

   vsSemaphore()
vsSemaphore ( const vsSemaphore& copy);

Creates a copy of an existing vsSemaphore.

   ~vsSemaphore()
~vsSemaphore (  );

Destroys this vsSemaphore. If threads are currently waiting for the semaphore when destroyed, the results are undefined.

   getValue()
int getValue (  );

Returns the current semaphore count. Note: Win32 platform does not support retrieving the value of a semaphore. getValue on Win32 tracks the value and returns it without being atomic.

   post()
vsBool post (  );

Increments the count of the semaphore and awakens the first waiting thread. This function returns TRUE unless an error occurs.

   trywait()
vsBool trywait (  );

Similar to wait() but never block the calling thread. If the semaphore does not have a positive value when this function is invoked, the semaphore will not be modified and FALSE is returned; otherwise TRUE is returned and the effect is exactly that of wait().

   wait()
vsBool wait (  );

Decrements the semaphore count. If the new count is negative, the semaphore will block the calling thread until the count is incremented (see post()). This function returns TRUE unless an error occurs.

SEE ALSO
vsThread