UaSemaphore Class Reference
[UA Base Library Classes]

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 plane copies of this Class. It is not possible to use the default constructor. More...

#include <uasemaphore.h>

List of all members.


Public Member Functions

 UaSemaphore (OpcUa_UInt32 initalValue, OpcUa_UInt32 maxRange)
 ~UaSemaphore ()
OpcUa_StatusCode wait ()
OpcUa_StatusCode timedWait (OpcUa_UInt32 msecTimeout)
OpcUa_StatusCode post (OpcUa_UInt32 releaseCount)

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 plane 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:
initalValue Specifies 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 nonsignaled when it is zero.
maxRange Specifies the maximum count for the semaphore object. This value must be greater than zero.

UaSemaphore::~UaSemaphore (  ) 

Destruction Destroys the UaSemaphore object.


Member Function Documentation

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_GoodNonCriticalTimeout if the Semaphore is in nonsignaled stte and the wait reached a timeout, OpcUa_BadInternalError if an error occurred in the wait 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:
msecTimeout Timeout in milliseconds.
Returns:
OpcUa_Good if the Semaphore is in signaled state, OpcUa_GoodNonCriticalTimeout if the Semaphore is in nonsignaled stte and the wait reached the passed timeout, OpcUa_BadInternalError if an error occurred in the wait function

OpcUa_StatusCode UaSemaphore::post ( OpcUa_UInt32  releaseCount  ) 

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

See also:
wait()
Parameters:
releaseCount Specifies 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


The documentation for this class was generated from the following files:
  • src/uabase/uabasecpp/uasemaphore.h
  • src/uabase/uabasecpp/uasemaphore.cpp