Newton Dynamics  4.00
dSemaphore Class Reference

Generic counting semaphore for thread synchronization. More...

Inheritance diagram for dSemaphore:
dThread dThreadPool ndScene ndSceneMixed ndWorldScene< ndSceneMixed > ndWorldMixedScene ndWorldSegregatedScene

Public Member Functions

D_CORE_API dSemaphore ()
 Create and initialize counter to zero.
 
D_CORE_API ~dSemaphore ()
 Destroy semaphore.
 
D_CORE_API dInt32 GetCount () const
 Returns counter counter value.
 
D_CORE_API bool Wait ()
 Synchronize with another threads. More...
 
D_CORE_API void Signal ()
 Notify a thread blocked by member function Wait to wake and test m_counter again. More...
 
D_CORE_API void Terminate ()
 Notify a waiting thread on member function Wait that is time to exit the thread loop.
 

Detailed Description

Generic counting semaphore for thread synchronization.

Member Function Documentation

◆ Signal()

void dSemaphore::Signal ( )

Notify a thread blocked by member function Wait to wake and test m_counter again.

Increment internal variable m_count by one and signal the thread to wakeup.

◆ Wait()

bool dSemaphore::Wait ( )

Synchronize with another threads.

Returns
returns false if member function Terminate has not been called.

When internal variable m_counter is zero, this function blocks the calling thread until another thread call Signal function incrementing m_count by one.

when counter is hight that zero, this function return immediately decrementing the m_count by one.