reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
scheduler.h File Reference

Scheduler API for the threaded C runtime. More...

#include "lf_types.h"
#include "scheduler_instance.h"

Go to the source code of this file.

Functions

void lf_sched_init (environment_t *env, size_t number_of_workers, sched_params_t *parameters)
 Initialize the scheduler.
 
void lf_sched_free (lf_scheduler_t *scheduler)
 Free the memory used by the scheduler.
 
reaction_tlf_sched_get_ready_reaction (lf_scheduler_t *scheduler, int worker_number)
 Ask the scheduler for one more reaction.
 
void lf_sched_done_with_reaction (size_t worker_number, reaction_t *done_reaction)
 Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.
 
void lf_scheduler_trigger_reaction (lf_scheduler_t *scheduler, reaction_t *reaction, int worker_number)
 Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.
 

Detailed Description

Scheduler API for the threaded C runtime.

Author
Soroush Bateni
Edward A. Lee

A scheduler for the threaded runtime of reactor-c should provide an implementation for functions that are defined in this header file.

Function Documentation

◆ lf_sched_done_with_reaction()

void lf_sched_done_with_reaction ( size_t worker_number,
reaction_t * done_reaction )

Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.

Parameters
schedulerThe scheduler
worker_numberThe worker number for the worker thread that has finished executing 'done_reaction'.
done_reactionThe reaction that is done.
worker_numberThe worker number for the worker thread that has finished executing 'done_reaction'.
done_reactionThe reaction that is done.

◆ lf_sched_free()

void lf_sched_free ( lf_scheduler_t * scheduler)

Free the memory used by the scheduler.

Parameters
schedulerThe scheduler

This must be called when the scheduler is no longer needed.

This must be called when the scheduler is no longer needed.

◆ lf_sched_get_ready_reaction()

reaction_t * lf_sched_get_ready_reaction ( lf_scheduler_t * scheduler,
int worker_number )

Ask the scheduler for one more reaction.

This function blocks until it can return a ready reaction for worker thread 'worker_number' or it is time for the worker thread to stop and exit (where a NULL value would be returned). This function assumes that the environment mutex is not locked.

Parameters
schedulerThe scheduler
worker_numberFor the calling worker thread.
Returns
reaction_t* A reaction for the worker to execute. NULL if the calling worker thread should exit.

This function blocks until it can return a ready reaction for worker thread 'worker_number' or it is time for the worker thread to stop and exit (where a NULL value would be returned).

Parameters
worker_number
Returns
reaction_t* A reaction for the worker to execute. NULL if the calling worker thread should exit.

◆ lf_sched_init()

void lf_sched_init ( environment_t * env,
size_t number_of_workers,
sched_params_t * params )

Initialize the scheduler.

This has to be called before other functions of the scheduler can be used. If the scheduler is already initialized, this will be a no-op.

Parameters
envThe environment in which we should initialize the scheduler
number_of_workersIndicate how many workers this scheduler will be managing.
optionPointer to a sched_params_t struct containing additional scheduler parameters. Can be NULL.

This has to be called before other functions of the scheduler can be used. If the scheduler is already initialized, this will be a no-op.

Parameters
envEnvironment within which we are executing.
number_of_workersIndicate how many workers this scheduler will be managing.
optionPointer to a sched_params_t struct containing additional scheduler parameters.

◆ lf_scheduler_trigger_reaction()

void lf_scheduler_trigger_reaction ( lf_scheduler_t * scheduler,
reaction_t * reaction,
int worker_number )

Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.

If a worker number is not available (e.g., this function is not called by a worker thread), -1 should be passed as the 'worker_number'.

The scheduler will ensure that the same reaction is not triggered twice in the same tag.

Parameters
schedulerThe scheduler
reactionThe reaction to trigger at the current tag.
worker_numberThe ID of the worker that is making this call. 0 should be used if there is only one worker (e.g., when the program is using the single-threaded C runtime). -1 is used for an anonymous call in a context where a worker number does not make sense (e.g., the caller is not a worker thread).

If a worker number is not available (e.g., this function is not called by a worker thread), -1 should be passed as the 'worker_number'.

This scheduler ignores the worker number.

The scheduler will ensure that the same reaction is not triggered twice in the same tag.

Parameters
reactionThe reaction to trigger at the current tag.
worker_numberThe ID of the worker that is making this call. 0 should be used if there is only one worker (e.g., when the program is using the single-threaded C runtime). -1 is used for an anonymous call in a context where a worker number does not make sense (e.g., the caller is not a worker thread).