Isle
Loading...
Searching...
No Matches
MxSemaphore Class Reference

Implements a lightweight wrapper for Windows semaphores, allowing safe synchronization between threads. More...

#include <mxsemaphore.h>

Public Member Functions

 MxSemaphore ()
 Constructs the MxSemaphore object; initializes internal handle to NULL. More...
 
 ~MxSemaphore ()
 Destructor, closes the semaphore handle if open. More...
 
virtual MxResult Init (MxU32 p_initialCount, MxU32 p_maxCount)
 Initializes the semaphore with both initial and maximum counts. More...
 
void Wait (MxU32 p_timeoutMS)
 Waits on the semaphore for the specified timeout (in milliseconds). More...
 
void Release (MxU32 p_releaseCount)
 Increases the semaphore count, unblocking waiting threads if any. More...
 

Detailed Description

Implements a lightweight wrapper for Windows semaphores, allowing safe synchronization between threads.

[AI]

[AI] MxSemaphore provides methods for initializing, waiting on, and releasing a Windows semaphore object, supporting cross-thread signaling and limiting concurrent execution. Used as a utility for resource management, thread pool gates, and similar concurrency control. [AI]

Definition at line 15 of file mxsemaphore.h.

Constructor & Destructor Documentation

◆ MxSemaphore()

MxSemaphore::MxSemaphore ( )

Constructs the MxSemaphore object; initializes internal handle to NULL.

[AI]

Definition at line 9 of file mxsemaphore.cpp.

◆ ~MxSemaphore()

MxSemaphore::~MxSemaphore ( )
inline

Destructor, closes the semaphore handle if open.

[AI]

[AI] This cleans up OS resources, preventing handle leaks.

Definition at line 26 of file mxsemaphore.h.

Member Function Documentation

◆ Init()

MxResult MxSemaphore::Init ( MxU32  p_initialCount,
MxU32  p_maxCount 
)
virtual

Initializes the semaphore with both initial and maximum counts.

[AI]

Parameters
p_initialCountThe initial count for the semaphore (i.e., how many Wait() calls will succeed before blocking). [AI]
p_maxCountThe maximum value the semaphore count can reach. [AI]
Returns
SUCCESS on success, FAILURE otherwise. [AI]

[AI] Allocates the Windows semaphore resource and prepares it for use. Subsequent Wait and Release calls must only occur after successful initialization. [AI]

Definition at line 15 of file mxsemaphore.cpp.

◆ Release()

void MxSemaphore::Release ( MxU32  p_releaseCount)

Increases the semaphore count, unblocking waiting threads if any.

[AI]

Parameters
p_releaseCountIncrement amount for the semaphore's internal counter; typically 1 for single-release. [AI]

[AI] Allows up to p_releaseCount threads blocked in Wait to proceed. [AI]

Definition at line 33 of file mxsemaphore.cpp.

◆ Wait()

void MxSemaphore::Wait ( MxU32  p_timeoutMS)

Waits on the semaphore for the specified timeout (in milliseconds).

[AI]

Parameters
p_timeoutMSTimeout in milliseconds to wait before the operation is considered unsuccessful. [AI]

[AI] Decrements the semaphore counter if it is positive, otherwise blocks for up to the specified timeout unless Release is called from another thread. [AI]

Definition at line 27 of file mxsemaphore.cpp.


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