NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
Public Member Functions | List of all members
BiometricEvaluation::Process::Semaphore Class Reference

Represent a semaphore that can be used for interprocess communication. More...

#include <be_process_semaphore.h>

Public Member Functions

 Semaphore (const std::string &name, const mode_t mode, const int value, const bool force=false)
 Create a new named sempahore. More...
 
 Semaphore (const std::string &name)
 Open an existing named sempahore. More...
 
 ~Semaphore ()
 
bool wait (const bool interruptible)
 Wait indefinitely for the semaphore to unblock. More...
 
bool trywait (const bool interruptible)
 Attempt to obtain the semaphore without blocking. More...
 
bool timedwait (const uint64_t interval, const bool interruptible)
 Attempt to obtain the semaphore while blocking for at most the specified time interval. More...
 
void post ()
 Post (increment) to the semaphore. More...
 
std::string getName ()
 Obtain the name of the Semaphore. More...
 

Detailed Description

Represent a semaphore that can be used for interprocess communication.

Semaphores are shared counters with mutually exclusive modification properties. A counter value greater than zero means that a resource represented by the semaphore is available. A typical use is to grant exclusive access to a resource by allowing the counter to be valued at zero or one; this is known as a binary semaphore.

Note
The counter value is not exposed to clients of the object.
Because a Semaphore object wraps a system resource, the Semaphore can be passed to other functions, or inherited across a fork boundary.

Definition at line 42 of file be_process_semaphore.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

BiometricEvaluation::Process::Semaphore::Semaphore ( const std::string &  name,
const mode_t  mode,
const int  value,
const bool  force = false 
)

Create a new named sempahore.

Parameters
[in]nameThe name of the semaphore, which must obey the syntax documented for the sem_open(2) call. If the semaphore already exists in the name space, construction will fail unless the force flag is true. In that case, the existing semaphore will be removed.
[in]modeThe permission mode of the semaphore.
[in]valueThe initial value of the semaphore.
[in]forceThe semaphore is created, disassociating an existing semaphore of the same name.
Exceptions
Error::ObjectExistsThe semaphore already exists with the given name.
Error::StrategyErrorAn error occurred when creating the semaphore.

◆ Semaphore() [2/2]

BiometricEvaluation::Process::Semaphore::Semaphore ( const std::string &  name)

Open an existing named sempahore.

Parameters
[in]nameThe name of the semaphore, which must obey the syntax documented for the sem_open(2) call.
Exceptions
Error::ObjectDoesNotExistA semaphore does not exist with the given name.
Error::StrategyErrorAn error occurred when creating the semaphore.

◆ ~Semaphore()

BiometricEvaluation::Process::Semaphore::~Semaphore ( )

Member Function Documentation

◆ wait()

bool BiometricEvaluation::Process::Semaphore::wait ( const bool  interruptible)

Wait indefinitely for the semaphore to unblock.

Parameters
[in]interruptibletrue if the function should return if waiting was interrupted, false otherwise.
Returns
true if the semaphore was obtained; false if not.
Exceptions
Error::ObjectDoesNotExistThe semaphore is no longer valid.
Error::StrategyErrorSystem error obtaining the semaphore.

◆ trywait()

bool BiometricEvaluation::Process::Semaphore::trywait ( const bool  interruptible)

Attempt to obtain the semaphore without blocking.

Parameters
[in]interruptibletrue if the function should return if waiting was interrupted, false otherwise.
Returns
true if the semaphore was obtained; false if not.
Exceptions
Error::ObjectDoesNotExistThe semaphore is no longer valid.
Error::StrategyErrorSystem error obtaining the semaphore.

◆ timedwait()

bool BiometricEvaluation::Process::Semaphore::timedwait ( const uint64_t  interval,
const bool  interruptible 
)

Attempt to obtain the semaphore while blocking for at most the specified time interval.

Parameters
[in]intervalThe max time to wait, in microseconds.
[in]interruptibletrue if the function should return if waiting was interrupted, false otherwise.
Returns
true if the semaphore was obtained; false if not.
Exceptions
Error::ObjectDoesNotExistThe semaphore is no longer valid.
Error::NotImplementedFunction is not implemented on the system. Applications should then call wait() or trywait().
Error::StrategyErrorSystem error obtaining the semaphore.

◆ post()

void BiometricEvaluation::Process::Semaphore::post ( )

Post (increment) to the semaphore.

Exceptions
Error::ObjectDoesNotExistThe semaphore is no longer valid.
Error::StrategyErrorSystem error obtaining the semaphore.

◆ getName()

std::string BiometricEvaluation::Process::Semaphore::getName ( )

Obtain the name of the Semaphore.

Returns
The name of the Sempahore.

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