S2OPC OPCUA Toolkit
Functions
sopc_threads.h File Reference

A platform independent API to use threads. More...

#include "p_sopc_threads.h"

Go to the source code of this file.

Functions

SOPC_ReturnStatus SOPC_Thread_Create (SOPC_Thread *thread, void *(*startFct)(void *), void *startArgs, const char *taskName)
 Function to create a thread. More...
 
SOPC_ReturnStatus SOPC_Thread_CreatePrioritized (SOPC_Thread *thread, void *(*startFct)(void *), void *startArgs, int priority, const char *taskName)
 Function to create a high priority thread. More...
 
SOPC_ReturnStatus SOPC_Thread_Join (SOPC_Thread thread)
 Function to wait for a thread to terminate. More...
 

Detailed Description

A platform independent API to use threads.

Function Documentation

◆ SOPC_Thread_Create()

SOPC_ReturnStatus SOPC_Thread_Create ( SOPC_Thread thread,
void *(*)(void *)  startFct,
void *  startArgs,
const char *  taskName 
)

Function to create a thread.

The platform-specific implementation of "p_threads.h" shall provide the actual definition of

  • SOPC_Condition for Condition Variables (e.g. pthread_mutex_t for LINUX)
  • SOPC_Mutex for Mutexes. (e.g. pthread_cond_t for LINUX)
  • SOPC_Thread for threads (e.g. pthread_t for linux)
    Parameters
    threadReturn parameter for the created thread
    startFctFunction called at thread start. The startFct function is called in a new thread context with startArgs as parameter. The return value is not relevant and shall be set to NULL.
    startArgsArguments of the start function
    taskNameName of the created thread
    Returns
    SOPC_STATUS_OK if operation succeeded, SOPC_STATUS_INVALID_PARAMETERS or SOPC_STATUS_NOK otherwise.
    Note
    The created thread must be joined using SOPC_Thread_Join to ensure context deletion.
    Warning
    Depending on platform, the taskName length might be limited (e.g.: 16 characters including terminating null byte for POSIX). In this case the taskName will be truncated to comply with limitation.

◆ SOPC_Thread_CreatePrioritized()

SOPC_ReturnStatus SOPC_Thread_CreatePrioritized ( SOPC_Thread thread,
void *(*)(void *)  startFct,
void *  startArgs,
int  priority,
const char *  taskName 
)

Function to create a high priority thread.

Note
Only supported under Linux for now.

See SOPC_Thread_Create. This function creates a thread with specific priority, which usually requires administrative privileges. It should only be used to create threads that require to be woken up at regular but small intervals (< 1ms). Note that this interface does not specify the 'order' of priorities regarding the value. (typically on Zephyr, lower values are the highest priorities, whereas on Linux, this is the contrary).

Parameters
threadReturn parameter for the created thread
startFctFunction called at thread start
startArgsArguments of the start function
priorityPriority of the thread (range depends on implementation) : Linux: 1 .. 99, FreeRTOS: 1 .. configMAX_PRIORITIES ZEPHYR: 1 .. CONFIG_NUM_COOP_PRIORITIES + CONFIG_NUM_PREEMPT_PRIORITIES. Note that this is a simple offset of (CONFIG_NUM_COOP_PRIORITIES + 1) regarding the Zephyr native priorities. This is required to ensure consistency with S2OPC interface. In prj.conf, the priorities configured MUST take into account this offset.
taskNameName of the created thread
Note
The created thread must be joined using SOPC_Thread_Join to ensure context deletion.
Returns
SOPC_STATUS_OK if operation succeeded, SOPC_STATUS_INVALID_PARAMETERS or SOPC_STATUS_NOK otherwise.

◆ SOPC_Thread_Join()

SOPC_ReturnStatus SOPC_Thread_Join ( SOPC_Thread  thread)

Function to wait for a thread to terminate.

Parameters
threadThread to wait for, created either by SOPC_Thread_Create or SOPC_Thread_CreatePrioritized. Each thread can and shall be joined once only when terminating.