Vault
4.1
|
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>
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. |
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.
Waits until the semaphore is signaled by another thread.
ownedMutex | the mutex that the caller has already acquired the lock for |
timeoutInterval | zero 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.
semaphore | pointer to the platform semaphore |
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.
semaphore | pointer to the platform semaphore |
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.
semaphore | pointer to the platform semaphore |
mutex | pointer to a locked platform mutex that the calling thread had acquired; this function unlocks it while waiting and locks it upon return |
timeoutInterval | zero for no timeout; otherwise, the interval after which to timeout |
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.
semaphore | pointer to the platform semaphore |
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.
semaphore | pointer to the platform semaphore |
Definition at line 178 of file vthread_platform.cpp.