TracktionEngine
Public Member Functions | List of all members
tracktion::graph::LightweightSemaphore Class Reference

A counting semaphore that spins on a atomic before waiting so will avoid system calls if wait periods are very short. More...

Public Member Functions

 LightweightSemaphore (int initialCount=0)
 Creates a semaphore with an initial count. More...
 
 ~LightweightSemaphore ()
 Destructor. More...
 
bool wait ()
 Decrements the count by one and if the result of this goes below zero the call will block. More...
 
bool try_wait ()
 Attemps to decrement the count by one. More...
 
bool timed_wait (std::uint64_t usecs)
 Performs a wait operation. More...
 
void signal (int count=1)
 Increases the count by the ammount specified. More...
 

Detailed Description

A counting semaphore that spins on a atomic before waiting so will avoid system calls if wait periods are very short.

Constructor & Destructor Documentation

◆ LightweightSemaphore()

tracktion::graph::LightweightSemaphore::LightweightSemaphore ( int  initialCount = 0)

Creates a semaphore with an initial count.

◆ ~LightweightSemaphore()

tracktion::graph::LightweightSemaphore::~LightweightSemaphore ( )

Destructor.

Member Function Documentation

◆ wait()

bool tracktion::graph::LightweightSemaphore::wait ( )

Decrements the count by one and if the result of this goes below zero the call will block.

Returns
true if the decrement actually happened or false if there was a problem (like the maximum count has been exceeded)

◆ try_wait()

bool tracktion::graph::LightweightSemaphore::try_wait ( )

Attemps to decrement the count by one.

If the decrement leaves the count above zero this will return true. If the decrement would leave the count below zero this will not block and return false.

◆ timed_wait()

bool tracktion::graph::LightweightSemaphore::timed_wait ( std::uint64_t  usecs)

Performs a wait operation.

If the wait would actually block, the block happens for the given period of time before returning or the semaphore is signalled, whichever happens first.

Returns
true if the decrement actually happened or false if the count would have gone below zero and this had to block.

◆ signal()

void tracktion::graph::LightweightSemaphore::signal ( int  count = 1)

Increases the count by the ammount specified.

If the count goes above zero, this will signal waiting threads, unblocking them.


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