S2OPC OPCUA Toolkit
Functions
sopc_mutexes.h File Reference

A platform independent API to use mutexes and condition variables. More...

#include <stdint.h>
#include "sopc_enums.h"
#include "sopc_threads.h"

Go to the source code of this file.

Functions

SOPC_ReturnStatus SOPC_Condition_Init (SOPC_Condition *cond)
 Create a Condition variable. More...
 
SOPC_ReturnStatus SOPC_Condition_Clear (SOPC_Condition *cond)
 Delete a Condition variable. More...
 
SOPC_ReturnStatus SOPC_Condition_SignalAll (SOPC_Condition *cond)
 Signals the condition variable to all waiting threads. More...
 
SOPC_ReturnStatus SOPC_Mutex_Initialization (SOPC_Mutex *mut)
 Create a Mutex. More...
 
SOPC_ReturnStatus SOPC_Mutex_Clear (SOPC_Mutex *mut)
 Delete a Mutex. More...
 
SOPC_ReturnStatus SOPC_Mutex_Lock (SOPC_Mutex *mut)
 Lock a Mutex. The function may be blocking as long as the mutex is locked by another thread. More...
 
SOPC_ReturnStatus SOPC_Mutex_Unlock (SOPC_Mutex *mut)
 Release a Mutex. More...
 
SOPC_ReturnStatus SOPC_Mutex_UnlockAndWaitCond (SOPC_Condition *cond, SOPC_Mutex *mut)
 Wait for a condition variable notification. More...
 
SOPC_ReturnStatus SOPC_Mutex_UnlockAndTimedWaitCond (SOPC_Condition *cond, SOPC_Mutex *mut, uint32_t milliSecs)
 Timed wait for a condition variable notification. More...
 

Detailed Description

A platform independent API to use mutexes and condition variables.

Mutexes are recursive, and lock can be called inside a thread where the lock is already held without blocking.

Function Documentation

◆ SOPC_Condition_Init()

SOPC_ReturnStatus SOPC_Condition_Init ( SOPC_Condition cond)

Create a Condition variable.

Parameters
condA non-NULL pointer to a condition to be created
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Condition_Clear()

SOPC_ReturnStatus SOPC_Condition_Clear ( SOPC_Condition cond)

Delete a Condition variable.

Parameters
condA non-NULL pointer to a condition to be deleted
Note
The related MUTEX shall be unlocked and shall be deleted after the condition variable
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Condition_SignalAll()

SOPC_ReturnStatus SOPC_Condition_SignalAll ( SOPC_Condition cond)

Signals the condition variable to all waiting threads.

Parameters
condA non-NULL pointer to a condition to be signaled
Returns
SOPC_STATUS_OK in case of success
Note
Must be called between lock and unlock of dedicated Mutex

◆ SOPC_Mutex_Initialization()

SOPC_ReturnStatus SOPC_Mutex_Initialization ( SOPC_Mutex mut)

Create a Mutex.

Parameters
mutA non-NULL pointer to a Mutex to be created
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Mutex_Clear()

SOPC_ReturnStatus SOPC_Mutex_Clear ( SOPC_Mutex mut)

Delete a Mutex.

Parameters
mutA non-NULL pointer to a Mutex to be deleted
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Mutex_Lock()

SOPC_ReturnStatus SOPC_Mutex_Lock ( SOPC_Mutex mut)

Lock a Mutex. The function may be blocking as long as the mutex is locked by another thread.

Note
Mutex shall be recursive. (The same thread can lock several times the same mutex without being blocked)
Parameters
mutA non-NULL pointer to a Mutex to be locked
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Mutex_Unlock()

SOPC_ReturnStatus SOPC_Mutex_Unlock ( SOPC_Mutex mut)

Release a Mutex.

Parameters
mutA non-NULL pointer to a Mutex to be unlocked
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Mutex_UnlockAndWaitCond()

SOPC_ReturnStatus SOPC_Mutex_UnlockAndWaitCond ( SOPC_Condition cond,
SOPC_Mutex mut 
)

Wait for a condition variable notification.

Parameters
condA non-NULL pointer to a Condition variable to wait for
mutA non-NULL pointer to the related Mutex. This Mutex shall be locked by caller before call and unlocked after return.
Returns
SOPC_STATUS_OK in case of success

◆ SOPC_Mutex_UnlockAndTimedWaitCond()

SOPC_ReturnStatus SOPC_Mutex_UnlockAndTimedWaitCond ( SOPC_Condition cond,
SOPC_Mutex mut,
uint32_t  milliSecs 
)

Timed wait for a condition variable notification.

Parameters
condA non-NULL pointer to a Condition variable to wait for
mutA non-NULL pointer to the related Mutex. This Mutex shall be locked by caller before call and unlocked after return.
milliSecsThe maximum amount of wait time.
Returns
SOPC_STATUS_OK in case of success. SOPC_STATUS_TIMEOUT if the condition is not received within the requested timeout