WPILibC++ 2024.3.2
wpi::Semaphore Class Referencefinal

A semaphore for synchronization. More...

#include <wpi/Synchronization.h>

Public Member Functions

 Semaphore (int initialCount=0, int maximumCount=INT_MAX)
 Constructor. More...
 
 ~Semaphore ()
 
 Semaphore (const Semaphore &)=delete
 
Semaphoreoperator= (const Semaphore &)=delete
 
 Semaphore (Semaphore &&rhs)
 
Semaphoreoperator= (Semaphore &&rhs)
 
 operator WPI_Handle () const
 Gets the semaphore handle (e.g. More...
 
WPI_SemaphoreHandle GetHandle () const
 Gets the semaphore handle (e.g. More...
 
bool Release (int releaseCount=1, int *prevCount=nullptr)
 Releases N counts of the semaphore. More...
 

Detailed Description

A semaphore for synchronization.

Semaphores keep an internal counter. Releasing the semaphore increases the count. A semaphore with a non-zero count is considered signaled. When a waiter wakes up it atomically decrements the count by 1. This is generally useful in a single-supplier, multiple-consumer scenario.

Constructor & Destructor Documentation

◆ Semaphore() [1/3]

wpi::Semaphore::Semaphore ( int  initialCount = 0,
int  maximumCount = INT_MAX 
)
inlineexplicit

Constructor.

Parameters
initialCountinitial value for the semaphore's internal counter
maximumCountmaximum value for the samephore's internal counter

◆ ~Semaphore()

wpi::Semaphore::~Semaphore ( )
inline

◆ Semaphore() [2/3]

wpi::Semaphore::Semaphore ( const Semaphore )
delete

◆ Semaphore() [3/3]

wpi::Semaphore::Semaphore ( Semaphore &&  rhs)
inline

Member Function Documentation

◆ GetHandle()

WPI_SemaphoreHandle wpi::Semaphore::GetHandle ( ) const
inline

Gets the semaphore handle (e.g.

for WaitForObject).

Returns
handle

◆ operator WPI_Handle()

wpi::Semaphore::operator WPI_Handle ( ) const
inlineexplicit

Gets the semaphore handle (e.g.

for WaitForObject).

Returns
handle

◆ operator=() [1/2]

Semaphore & wpi::Semaphore::operator= ( const Semaphore )
delete

◆ operator=() [2/2]

Semaphore & wpi::Semaphore::operator= ( Semaphore &&  rhs)
inline

◆ Release()

bool wpi::Semaphore::Release ( int  releaseCount = 1,
int *  prevCount = nullptr 
)
inline

Releases N counts of the semaphore.

Parameters
releaseCountamount to add to semaphore's internal counter; must be positive
prevCountif non-null, previous count (output parameter)
Returns
True on successful release, false on failure (e.g. release count would exceed maximum value, or handle invalid)

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