Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Semaphore Class Reference

Core class that represents a counting semaphore. More...

Public Member Functions

 Semaphore (unsigned int count)
 Constructs a semaphore object with a count.
 
 Semaphore (const Semaphore &)=delete
 
 Semaphore (Semaphore &&) noexcept=default
 
 ~Semaphore ()
 Destructs the object.
 
unsigned int GetCount () const
 Gets the number of count that can handle the semaphore. More...
 
void Post ()
 Increments the count of the semaphore and wait if count equals zero. More...
 
void Wait ()
 Decrements the count of the semaphore and wait if count equals zero. More...
 
bool Wait (UInt32 timeout)
 Decrements the count of the semaphore and wait if count equals zero. More...
 
Semaphoreoperator= (const Semaphore &)=delete
 
Semaphoreoperator= (Semaphore &&) noexcept=default
 

Detailed Description

Core class that represents a counting semaphore.

Member Function Documentation

◆ GetCount()

unsigned int Nz::Semaphore::GetCount ( ) const

Gets the number of count that can handle the semaphore.

Returns
Number of count associated with the semaphore

◆ Post()

void Nz::Semaphore::Post ( )

Increments the count of the semaphore and wait if count equals zero.

Increments the value of semaphore variable by 1. After the increment, if the pre-increment value was negative (meaning there are processes waiting for a resource), it transfers a blocked process from the semaphore's waiting queue to the ready queue

◆ Wait() [1/2]

void Nz::Semaphore::Wait ( )

Decrements the count of the semaphore and wait if count equals zero.

If the value of semaphore variable is not negative, decrements it by 1. If the semaphore variable is now negative, the process executing Wait is blocked (i.e., added to the semaphore's queue) until the value is greater or equal to 1. Otherwise, the process continues execution, having used a unit of the resource

◆ Wait() [2/2]

bool Nz::Semaphore::Wait ( UInt32  timeout)

Decrements the count of the semaphore and wait if count equals zero.

Returns
true if the semaphore successfully decrements before timeout

If the value of semaphore variable is not negative, decrements it by 1. If the semaphore variable is now negative, the process executing Wait is blocked (i.e., added to the semaphore's queue) until the value is greater or equal to 1. Otherwise, the process continues execution, having used a unit of the resource


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