The ChBenaphore class implements the concept of a benaphore, which Benoit Schillings discussed in Issue #26 of the Be Newsletter.
A "benaphore" is basically a smart semaphore that attempts to avoid the overhead associated with the acquire_sem() and release_sem() calls.
#include "Ch/ChBenaphore.h" ChBenaphore( const char *name = "Benaphore" );
Create a new ChBenaphore object with a name of name.
~ChBenaphore();
Destroy the ChBenaphore; if you destroy a locked ChBenaphore, any threads waiting to acquire the lock will be unblocked and Lock() will return B_INTERRUPTED.
bool IsValid( void );
Returns true if the ChBenaphore is valid, or false if it's not. Currently, you can get an invalid ChBenaphore by providing the constructor with a name of NULL or if the create_sem() call inside the constructor fails.
You should always check to be sure your newly created ChBenaphore is valid before attempting to use it.
status_t Lock( void );
Lock the ChBenaphore. This will block until the lock succeeds.
Lock() will return B_NO_ERROR on success. If an error occurs, it will return B_INTERRUPTED or one of the acquire_sem() return values.
If Lock() returns B_INTERRUPTED you do not own the lock, so you should be careful about proceeding.
status_t LockTimeout( bigtime_t microseconds );
Lock the ChBenaphore, but stop trying after microseconds microseconds if unable to lock it.
LockTimeout() will return B_NO_ERROR, B_WOULD_BLOCK (if microseconds is 0), B_TIMED_OUT, or B_INTERRUPTED, much like acquire_sem_etc().
void Unlock( void );
Unlock the ChBenaphore. Calls to Lock() and Unlock() should match up; don't call Unlock() more than you call Lock(), for example.
Please see the libCh Overview for licensing information.
This implementation of the ChBenaphore class is © 1996-1998 Chris Herborth (chrish@kagi.com, based on information freely available in Issue #26 of the Be Developer's Newsletter.
Last modified: $Date: 1998/04/11 19:41:01 $