reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
lf_POSIX_threads_support.c File Reference
#include "low_level_platform.h"
#include "platform/lf_POSIX_threads_support.h"
#include "platform/lf_unix_clock_support.h"
#include <pthread.h>
#include <errno.h>
#include <stdint.h>
#include <unistd.h>

Functions

int lf_available_cores ()
 Get the number of cores on the host machine.
 
int lf_thread_create (lf_thread_t *thread, void *(*lf_thread)(void *), void *arguments)
 Helper function for creating a thread.
 
lf_thread_t lf_thread_self ()
 Return the lf_thread_t of the calling thread.
 
int lf_thread_join (lf_thread_t thread, void **thread_return)
 
int lf_mutex_init (lf_mutex_t *mutex)
 
int lf_mutex_lock (lf_mutex_t *mutex)
 
int lf_mutex_unlock (lf_mutex_t *mutex)
 
int lf_cond_init (lf_cond_t *cond, lf_mutex_t *mutex)
 
int lf_cond_broadcast (lf_cond_t *cond)
 
int lf_cond_signal (lf_cond_t *cond)
 
int lf_cond_wait (lf_cond_t *cond)
 
int _lf_cond_timedwait (lf_cond_t *cond, instant_t wakeup_time)
 

Function Documentation

◆ _lf_cond_timedwait()

int _lf_cond_timedwait ( lf_cond_t * cond,
instant_t wakeup_time )

Block the current thread on the condition variable until the condition variable pointed by "cond" is signaled or the time given by wakeup_time is reached. This should not be used directly as it does not account for clock synchronization offsets. Use lf_clock_cond_timedwait from clock.h instead.

Returns
0 on success, LF_TIMEOUT on timeout, and platform-specific error number otherwise.

◆ lf_available_cores()

int lf_available_cores ( )

Get the number of cores on the host machine.

◆ lf_cond_broadcast()

int lf_cond_broadcast ( lf_cond_t * cond)

Wake up all threads waiting for condition variable cond.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_cond_init()

int lf_cond_init ( lf_cond_t * cond,
lf_mutex_t * mutex )

Initialize a conditional variable.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_cond_signal()

int lf_cond_signal ( lf_cond_t * cond)

Wake up one thread waiting for condition variable cond.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_cond_wait()

int lf_cond_wait ( lf_cond_t * cond)

Wait for condition variable "cond" to be signaled or broadcast. The cond->mutex is assumed to be locked when this is called.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_mutex_init()

int lf_mutex_init ( lf_mutex_t * mutex)

Initialize a mutex.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_mutex_lock()

int lf_mutex_lock ( lf_mutex_t * mutex)

Lock a mutex.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_mutex_unlock()

int lf_mutex_unlock ( lf_mutex_t * mutex)

Unlock a mutex.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_thread_create()

int lf_thread_create ( lf_thread_t * thread,
void *(* lf_thread )(void *),
void * arguments )

Helper function for creating a thread.

Create a new thread, starting with execution of lf_thread getting passed arguments. The new handle is stored in thread_id.

Returns
0 on success, platform-specific error number otherwise.

◆ lf_thread_join()

int lf_thread_join ( lf_thread_t thread,
void ** thread_return )

Make calling thread wait for termination of the thread. The exit status of the thread is stored in thread_return if thread_return is not NULL.

Parameters
threadThe thread.
thread_returnA pointer to where to store the exit status of the thread.
Returns
0 on success, platform-specific error number otherwise.

◆ lf_thread_self()

lf_thread_t lf_thread_self ( )

Return the lf_thread_t of the calling thread.