Vault  4.1
Public Member Functions | Static Public Member Functions
VSemaphore Class Reference

VSemaphore implements a platform-independent semaphore that you can embed in an object or place on the stack to guarantee its cleanup when the VSemaphore object is destructed. More...

#include <vsemaphore.h>

List of all members.

Public Member Functions

 VSemaphore ()
 Creates and initializes the semaphore.
virtual ~VSemaphore ()
 Destructs the semaphore.
void wait (VMutex *ownedMutex, const VDuration &timeoutInterval)
 Waits until the semaphore is signaled by another thread.
void signal ()
 Signals the semaphore; if one or more other threads is waiting on the semaphore, exactly one of them will become unblocked by its wait() call returning.

Static Public Member Functions

static bool semaphoreInit (VSemaphore_Type *semaphore)
 Initializes the platform semaphore value.
static bool semaphoreDestroy (VSemaphore_Type *semaphore)
 Destroys the platform semaphore value.
static bool semaphoreWait (VSemaphore_Type *semaphore, VMutex_Type *mutex, const VDuration &timeoutInterval)
 Waits on the platform semaphore value.
static bool semaphoreSignal (VSemaphore_Type *semaphore)
 Signals the platform semaphore value.
static bool semaphoreBroadcast (VSemaphore_Type *semaphore)
 Broadcasts a signal the platform semaphore value; all threads waiting on the semaphore will unblock.

Detailed Description

VSemaphore implements a platform-independent semaphore that you can embed in an object or place on the stack to guarantee its cleanup when the VSemaphore object is destructed.

You can call the wait() and signal() methods to wait for a signal, and to unblock a waiter, respectively. To wait on a semaphore, you must supply a pointer to the VMutex that you have already acquired -- a semaphore is implicitly linked with a mutex.

Definition at line 31 of file vsemaphore.h.


Member Function Documentation

void VSemaphore::wait ( VMutex ownedMutex,
const VDuration timeoutInterval 
)

Waits until the semaphore is signaled by another thread.

Parameters:
ownedMutexthe mutex that the caller has already acquired the lock for
timeoutIntervalzero for no timeout; otherwise, the amount of time after which to timeout

Definition at line 28 of file vsemaphore.cpp.

References VMutex::getMutex(), and semaphoreWait().

bool VSemaphore::semaphoreInit ( VSemaphore_Type *  semaphore) [static]

Initializes the platform semaphore value.

Wrapper on Unix for pthread_cond_init.

Parameters:
semaphorepointer to the platform semaphore
Returns:
true on success; false on failure

Definition at line 140 of file vthread_platform.cpp.

References NULL.

bool VSemaphore::semaphoreDestroy ( VSemaphore_Type *  semaphore) [static]

Destroys the platform semaphore value.

Wrapper on Unix for pthread_cond_semaphore.

Parameters:
semaphorepointer to the platform semaphore
Returns:
true on success; false on failure

Definition at line 145 of file vthread_platform.cpp.

bool VSemaphore::semaphoreWait ( VSemaphore_Type *  semaphore,
VMutex_Type *  mutex,
const VDuration timeoutInterval 
) [static]

Waits on the platform semaphore value.

Wrapper on Unix for pthread_cond_wait.

Parameters:
semaphorepointer to the platform semaphore
mutexpointer to a locked platform mutex that the calling thread had acquired; this function unlocks it while waiting and locks it upon return
timeoutIntervalzero for no timeout; otherwise, the interval after which to timeout
Returns:
true on success; false on failure; timeout is considered success

Definition at line 150 of file vthread_platform.cpp.

References CONST_S64, VInstant::getValue(), and VDuration::ZERO().

bool VSemaphore::semaphoreSignal ( VSemaphore_Type *  semaphore) [static]

Signals the platform semaphore value.

Wrapper on Unix for pthread_cond_signal.

Parameters:
semaphorepointer to the platform semaphore
Returns:
true on success; false on failure

Definition at line 173 of file vthread_platform.cpp.

bool VSemaphore::semaphoreBroadcast ( VSemaphore_Type *  semaphore) [static]

Broadcasts a signal the platform semaphore value; all threads waiting on the semaphore will unblock.

Wrapper on Unix for pthread_cond_broadcast.

Parameters:
semaphorepointer to the platform semaphore
Returns:
true on success; false on failure

Definition at line 178 of file vthread_platform.cpp.


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.