All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::Semaphore Class Reference

Provides a general counting semaphore. More...

#include <Radiant/Semaphore.hpp>

Inheritance diagram for Radiant::Semaphore:
Patterns::NotCopyable

Public Member Functions

void acquire (int n=1)
 Try to acquire resources. More...
 
void release (int n=1)
 Release resources. More...
 
 Semaphore (int n=0)
 Initialize the semaphore to guard n resources. More...
 
bool tryAcquire (int n=1)
 Try to acquire resources. More...
 
bool tryAcquire (int n, int timeoutMs)
 Try to acquire resources. More...
 
 ~Semaphore ()
 Destructor.
 

Detailed Description

Provides a general counting semaphore.

Constructor & Destructor Documentation

Radiant::Semaphore::Semaphore ( int  n = 0)

Initialize the semaphore to guard n resources.

Parameters
nnumber of resources to guard (default 0)

Member Function Documentation

void Radiant::Semaphore::acquire ( int  n = 1)

Try to acquire resources.

This will block until available() >= n.

Parameters
nnumber of resources to acquire
void Radiant::Semaphore::release ( int  n = 1)

Release resources.

Parameters
nnumber of resources to release
bool Radiant::Semaphore::tryAcquire ( int  n = 1)

Try to acquire resources.

Does not block.

Parameters
nnumber of resources to acquire
Returns
true if requested resources were available, otherwise false
bool Radiant::Semaphore::tryAcquire ( int  n,
int  timeoutMs 
)

Try to acquire resources.

This call will block for at most the given timeout if available() < n.

Parameters
nnumber of resources to acquire
timeoutMstime to wait for resources if they are not avaible
Returns
true if requested resources were acquired, otherwise false