C++ Based OPC UA Client/Server/PubSub SDK  1.7.6.537

Semaphore class is used to allow threads to synchronize access to a resource. More...

#include <uasemaphore.h>

Public Member Functions

 UaSemaphore (OpcUa_UInt32 initalValue, OpcUa_UInt32 maxRange)
 Construction Constructs a UaSemaphore object that allows threads to synchronize access to a resource. More...
 
 ~UaSemaphore ()
 Destruction Destroys the UaSemaphore object.
 
OpcUa_StatusCode wait ()
 Wait until the Semaphore is in signaled state. More...
 
OpcUa_StatusCode timedWait (OpcUa_UInt32 msecTimeout)
 Wait until the Semaphore is in signaled state. More...
 
OpcUa_StatusCode post (OpcUa_UInt32 releaseCount)
 Increases the count of the specified semaphore object by a specified amount. More...
 

Detailed Description

Semaphore class is used to allow threads to synchronize access to a resource.

The UaSemaphore class provides a general counting semaphore. A semaphore is a generalization of a mutex. While a mutex can only be locked once, it's possible to acquire a semaphore multiple times. Semaphores are typically used to protect a certain number of identical resources. A typical application of semaphores is for controlling access to a circular buffer shared by a producer thread and a consumer thread. It is not possible to create shallow copies of this Class. It is not possible to use the default constructor.

Constructor & Destructor Documentation

UaSemaphore::UaSemaphore ( OpcUa_UInt32  initalValue,
OpcUa_UInt32  maxRange 
)

Construction Constructs a UaSemaphore object that allows threads to synchronize access to a resource.

Parameters
initalValueSpecifies an initial count for the semaphore object. This value must be greater than or equal to zero and less than or equal to maxCount. The state of a semaphore is signaled when its count is greater than zero and non signaled when it is zero.
maxRangeSpecifies the maximum count for the semaphore object. This value must be greater than zero.

Member Function Documentation

OpcUa_StatusCode UaSemaphore::post ( OpcUa_UInt32  releaseCount)

Increases the count of the specified semaphore object by a specified amount.

See also
wait()
Parameters
releaseCountSpecifies the amount by which the current count of the semaphore object is to be increased.
Returns
OpcUa_Good if the post function succeeded, OpcUa_BadInvalidArgument if the specified count was less than 1, OpcUa_BadInternalError if an error occurred in the post function
OpcUa_StatusCode UaSemaphore::timedWait ( OpcUa_UInt32  msecTimeout)

Wait until the Semaphore is in signaled state.

This function will block the current thread until the Semaphore is in signaled state or the passed timeout elapsed.

See also
post()
Parameters
msecTimeoutTimeout in milliseconds.
Returns
OpcUa_Good if the Semaphore is in signaled state, OpcUa_GoodNonCriticalTimeout if the Semaphore is in non signaled state and the wait reached the passed timeout, OpcUa_BadInternalError if an error occurred in the wait function
OpcUa_StatusCode UaSemaphore::wait ( )

Wait until the Semaphore is in signaled state.

This function will block the current thread until the Semaphore is in signaled state.

See also
post()
Returns
OpcUa_Good if the Semaphore is in signaled state, OpcUa_BadInternalError if an error occurred in the wait function

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