reactor-c
C Runtime for Lingua Franca
|
Platform API support for the C target of Lingua Franca. More...
Go to the source code of this file.
Data Structures | |
struct | lf_scheduling_policy_t |
Macros | |
#define | LF_TIMEOUT 1 |
#define | LF_SCHED_MAX_PRIORITY 99 |
#define | LF_SCHED_MIN_PRIORITY 0 |
#define | DEPRECATED(X) X |
Typedefs | |
typedef struct environment_t | environment_t |
Enumerations | |
enum | lf_scheduling_policy_type_t { LF_SCHED_FAIR , LF_SCHED_TIMESLICE , LF_SCHED_PRIORITY } |
The thread scheduling policies. More... | |
Functions | |
int | lf_notify_of_event (environment_t *env) |
Notify of new event. | |
int | lf_critical_section_enter (environment_t *env) |
Enter critical section within an environment. | |
int | lf_critical_section_exit (environment_t *env) |
Leave a critical section within an environment. | |
int | lf_available_cores () |
Get the number of cores on the host machine. | |
lf_thread_t | lf_thread_self () |
Return the lf_thread_t of the calling thread. | |
int | lf_thread_create (lf_thread_t *thread, void *(*lf_thread)(void *), void *arguments) |
Helper function for creating a thread. | |
int | lf_thread_join (lf_thread_t thread, void **thread_return) |
int | lf_thread_set_cpu (lf_thread_t thread, size_t cpu_number) |
Pin a thread to a specific CPU. | |
int | lf_thread_set_priority (lf_thread_t thread, int priority) |
Set the priority of a thread. Priority ranges from 0 to 99 where a higher number indicates higher priority. Setting the priority of a thread only makes sense if the thread is scheduled with LF_SCHED_TIMESLICE or LF_THREAD_PRIORITY. | |
int | lf_thread_set_scheduling_policy (lf_thread_t thread, lf_scheduling_policy_t *policy) |
Set the scheduling policy of a thread. This is based on the scheduling concept from Linux explained here: https://man7.org/linux/man-pages/man7/sched.7.html A scheduling policy is specific to a thread/worker. We have three policies LF_SCHED_PRIORITY which corresponds to SCHED_FIFO on Linux. LF_SCHED_TIMESLICE which corresponds to SCHED_RR on Linux. LF_SCHED_FAIR which corresponds to SCHED_OTHER on Linux. | |
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) |
int | lf_thread_id () |
Cross-platform version of the C11 thread_local keyword. | |
void | initialize_lf_thread_id () |
Initialize the thread ID for the current thread. | |
void | _lf_initialize_clock (void) |
int | _lf_clock_gettime (instant_t *t) |
int | lf_sleep (interval_t sleep_duration) |
int | _lf_interruptable_sleep_until_locked (environment_t *env, instant_t wakeup_time) |
Sleep until the given wakeup time. This should not be used directly as it does not account for clock synchronization offsets. See clock.h. | |
DEPRECATED (int lf_nanosleep(interval_t sleep_duration)) | |
Platform API support for the C target of Lingua Franca.
This file detects the platform on which the C compiler is being run (e.g. Windows, Linux, Mac) and conditionally includes platform-specific files that define core datatypes and function signatures for Lingua Franca.
#define LF_SCHED_MAX_PRIORITY 99 |
#define LF_SCHED_MIN_PRIORITY 0 |
#define LF_TIMEOUT 1 |
Fetch the value of an internal (and platform-specific) physical clock. Ideally, the underlying platform clock should be monotonic. However, the core lib enforces monotonicity at higher level APIs (see clock.h).
This should not be used directly as it does not apply clock synchronization offsets.
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.
Initialize the LF clock. Must be called before using other clock-related APIs.
int _lf_interruptable_sleep_until_locked | ( | environment_t * | env, |
instant_t | wakeup_time ) |
Sleep until the given wakeup time. This should not be used directly as it does not account for clock synchronization offsets. See clock.h.
This assumes the lock for the given environment is held.
env | The environment within which to sleep. |
wakeup_time | The time instant at which to wake up. |
DEPRECATED | ( | int | lf_nanosleepinterval_t sleep_duration | ) |
void initialize_lf_thread_id | ( | ) |
Initialize the thread ID for the current thread.
int lf_available_cores | ( | ) |
Get the number of cores on the host machine.
Wake up all threads waiting for condition variable cond.
int lf_cond_init | ( | lf_cond_t * | cond, |
lf_mutex_t * | mutex ) |
Initialize a conditional variable.
Wake up one thread waiting for condition variable cond.
Wait for condition variable "cond" to be signaled or broadcast. "mutex" is assumed to be locked before.
int lf_critical_section_enter | ( | environment_t * | env | ) |
Enter critical section within an environment.
env | Environment in which we are executing. |
Enter critical section within an environment.
env | Environment within which we are executing or GLOBAL_ENVIRONMENT. |
int lf_critical_section_exit | ( | environment_t * | env | ) |
Leave a critical section within an environment.
env | Environment in which we are executing. |
Leave a critical section within an environment.
env | Environment within which we are executing or GLOBAL_ENVIRONMENT. |
int lf_mutex_init | ( | lf_mutex_t * | mutex | ) |
Initialize a mutex.
int lf_mutex_lock | ( | lf_mutex_t * | mutex | ) |
Lock a mutex.
int lf_mutex_unlock | ( | lf_mutex_t * | mutex | ) |
Unlock a mutex.
int lf_notify_of_event | ( | environment_t * | env | ) |
Notify of new event.
env | Environment in which we are executing. |
Notify of new event.
env | Environment within which we are executing. |
int lf_sleep | ( | interval_t | sleep_duration | ) |
Pause execution for a given duration.
int lf_thread_create | ( | lf_thread_t * | thread, |
void *(*)(void *) | lf_thread, | ||
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.
int lf_thread_id | ( | ) |
Cross-platform version of the C11 thread_local keyword.
The ID of the current thread. The only guarantee is that these IDs will be a contiguous range of numbers starting at 0.
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.
thread | The thread. |
thread_return | A pointer to where to store the exit status of the thread. |
lf_thread_t lf_thread_self | ( | ) |
Return the lf_thread_t of the calling thread.
int lf_thread_set_cpu | ( | lf_thread_t | thread, |
size_t | cpu_number ) |
Pin a thread to a specific CPU.
thread | The thread |
cpu_number | the CPU ID |
int lf_thread_set_priority | ( | lf_thread_t | thread, |
int | priority ) |
Set the priority of a thread. Priority ranges from 0 to 99 where a higher number indicates higher priority. Setting the priority of a thread only makes sense if the thread is scheduled with LF_SCHED_TIMESLICE or LF_THREAD_PRIORITY.
thread | The thread. |
priority | The priority. |
int lf_thread_set_scheduling_policy | ( | lf_thread_t | thread, |
lf_scheduling_policy_t * | policy ) |
Set the scheduling policy of a thread. This is based on the scheduling concept from Linux explained here: https://man7.org/linux/man-pages/man7/sched.7.html A scheduling policy is specific to a thread/worker. We have three policies LF_SCHED_PRIORITY which corresponds to SCHED_FIFO on Linux. LF_SCHED_TIMESLICE which corresponds to SCHED_RR on Linux. LF_SCHED_FAIR which corresponds to SCHED_OTHER on Linux.