Benaphore 1.1

smart semaphore object

The Benaphore 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.


Constructor

Benaphore( const char *name  = "Benaphore" );

Create a new Benaphore object with a name of name.


Methods

bool isValid( void );

Returns TRUE if the Benaphore is valid, or FALSE if it's not. Currently, you can get an invalid Benaphore 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 Benaphore is valid before attempting to use it.

void Lock( void );

Lock the Benaphore. This will block until the lock succeeds.

void Unlock( void );

Unlock the Benaphore. Calls to Lock() and Unlock() should match up; don't call Unlock() more than you call Lock().


Copyright information

Availability

This implementation of the Benaphore class is © 1996 Chris Herborth (chrish@qnx.com, based on information freely available in Issue #26 of the Be Newsletter.

The code for Benaphore, and other BeOS-related information, is available on my web site in the Be section.

License

This code is freely usable by anyone for any purpose, as long as the author (Chris Herborth) is credited (in an application/library/other software product's documentation).

You may not charge for this code in any way. If this code is placed on an online service or CD-ROM, the service provider or CD-ROM publisher may not charge extra for this code or the space it occupies.

This documentation must accompany the source code (Benaphore.h and Benaphore.cpp), but you don't have to include the documentation or the source code with any software product that uses Benaphore objects internally.