Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentions of "unthreaded" replaced with "single-threaded" #250

Merged
merged 9 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
unit-tests-single:
uses: lf-lang/reactor-c/.github/workflows/unit-tests.yml@main
with:
cmake-args: '-UNUMBER_OF_WORKERS -DLF_UNTHREADED=1'
cmake-args: '-UNUMBER_OF_WORKERS -DLF_SINGLE_THREADED=1'

unit-tests-multi:
uses: lf-lang/reactor-c/.github/workflows/unit-tests.yml@main
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "Choose the type of build." FORCE)
endif()

# Whether or not we are using THREADED or UNTHREADEd runtime is a global
# Whether or not we are using THREADED or SINGLE-THREADED runtime is a global
# flag. If it is passed to cmake. Then add it as a global compile def which
# is inherited by all child nodes (add_subdirectory)
if(DEFINED LF_THREADED)
add_compile_definitions(LF_THREADED=1)
else()
add_compile_definitions(LF_UNTHREADED=1)
add_compile_definitions(LF_SINGLE_THREADED=1)
endif()

set(Test test)
Expand Down
8 changes: 4 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ list(APPEND INFO_SOURCES ${GENERAL_SOURCES})
# Create the core library
add_library(core ${GENERAL_SOURCES})

# Add sources for either threaded or unthreaded runtime
# Add sources for either threaded or single-threaded runtime
if (DEFINED FEDERATED)
include(federated/CMakeLists.txt)
endif()

# Add sources for either threaded or unthreaded runtime
# Add sources for either threaded or single-threaded runtime
if(DEFINED LF_THREADED)
message(STATUS "Including sources for threaded runtime with \
${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \
tracing=${LF_TRACE}.")
include(threaded/CMakeLists.txt)
else()
message(STATUS "Including sources for unthreaded runtime.")
message(STATUS "Including sources for single-threaded runtime.")
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
target_sources(core PRIVATE ${SINGLE_THREADED_SOURCES})
list(APPEND INFO_SOURCES ${SINGLE_THREADED_SOURCES})
Expand Down Expand Up @@ -105,7 +105,7 @@ define(FEDERATED_AUTHENTICATED)
define(LF_REACTION_GRAPH_BREADTH)
define(LF_THREADED)
define(LF_TRACE)
define(LF_UNTHREADED)
define(LF_SINGLE_THREADED)
define(LOG_LEVEL)
define(MODAL_REACTORS)
define(NUMBER_OF_FEDERATES)
Expand Down
14 changes: 7 additions & 7 deletions core/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ static void environment_init_threaded(environment_t* env, int num_workers) {
#endif
}
/**
* @brief Initialize the unthreaded-specific parts of the environment struct.
* @brief Initialize the single-threaded-specific parts of the environment struct.
*/
static void environment_init_unthreaded(environment_t* env) {
#ifdef LF_UNTHREADED
static void environment_init_single_threaded(environment_t* env) {
#ifdef LF_SINGLE_THREADED
// Reaction queue ordered first by deadline, then by level.
// The index of the reaction holds the deadline in the 48 most significant bits,
// the level in the 16 least significant bits.
Expand Down Expand Up @@ -132,8 +132,8 @@ static void environment_free_threaded(environment_t* env) {
#endif
}

static void environment_free_unthreaded(environment_t* env) {
#ifdef LF_UNTHREADED
static void environment_free_single_threaded(environment_t* env) {
#ifdef LF_SINGLE_THREADED
pqueue_free(env->reaction_q);
#endif
}
Expand Down Expand Up @@ -166,7 +166,7 @@ void environment_free(environment_t* env) {
pqueue_free(env->next_q);

environment_free_threaded(env);
environment_free_unthreaded(env);
environment_free_single_threaded(env);
environment_free_modes(env);
environment_free_federated(env);
trace_free(env->trace);
Expand Down Expand Up @@ -230,7 +230,7 @@ int environment_init(

// Initialize functionality depending on target properties.
environment_init_threaded(env, num_workers);
environment_init_unthreaded(env);
environment_init_single_threaded(env);
environment_init_modes(env, num_modes, num_state_resets);
environment_init_federated(env, num_is_present_fields);

Expand Down
4 changes: 2 additions & 2 deletions core/platform/lf_arduino_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int _lf_clock_now(instant_t* t) {
return 0;
}

#if defined(LF_UNTHREADED)
#if defined(LF_SINGLE_THREADED)

int lf_enable_interrupts_nested() {
if (_lf_num_nested_critical_sections++ == 0) {
Expand All @@ -152,7 +152,7 @@ int lf_disable_interrupts_nested() {
* Handle notifications from the runtime of changes to the event queue.
* If a sleep is in progress, it should be interrupted.
*/
int _lf_unthreaded_notify_of_event() {
int _lf_single_threaded_notify_of_event() {
_lf_async_event = true;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_linux_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define LF_MAX_SLEEP_NS USEC(UINT64_MAX)
#define LF_MIN_SLEEP_NS USEC(10)

#if defined LF_UNTHREADED
#if defined LF_SINGLE_THREADED
#include "lf_os_single_threaded_support.c"
#endif

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_macos_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "tag.h"
#define LF_MIN_SLEEP_NS USEC(10)

#if defined LF_UNTHREADED
#if defined LF_SINGLE_THREADED
#include "lf_os_single_threaded_support.c"
#endif

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_nrf52_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int lf_disable_interrupts_nested() {
*
* @return int
*/
int _lf_unthreaded_notify_of_event() {
int _lf_single_threaded_notify_of_event() {
_lf_async_event = true;
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions core/platform/lf_os_single_threaded_support.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined LF_UNTHREADED && !defined(PLATFORM_ARDUINO)
#if defined LF_SINGLE_THREADED && !defined(PLATFORM_ARDUINO)
/**
* @file lf_os_single_threaded_support.c
* @author Marten Lohstroh ([email protected])
Expand All @@ -16,7 +16,7 @@
#endif

/**
* @brief Unthreaded support under a OS is a special case in which we assume
* @brief Single-threaded support under a OS is a special case in which we assume
* only a single execution context. Other threads scheduling physical actions
* are not a use-case. ISRs scheduling physical actions are also not a use-case.
*
Expand All @@ -30,7 +30,7 @@ int lf_enable_interrupts_nested() {
return 0;
}

int _lf_unthreaded_notify_of_event() {
int _lf_single_threaded_notify_of_event() {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_windows_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int lf_nanosleep(interval_t sleep_duration) {
return lf_sleep(sleep_duration);
}

#if defined(LF_UNTHREADED)
#if defined(LF_SINGLE_THREADED)
#include "lf_os_single_threaded_support.c"
#endif

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_zephyr_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int lf_enable_interrupts_nested() {
}


int _lf_unthreaded_notify_of_event() {
int _lf_single_threaded_notify_of_event() {
_lf_async_event = true;
// If we are using the HI_RES clock. Then we interrupt a sleep through
// a semaphore. The LO_RES clock does a busy wait and is woken up by
Expand Down
14 changes: 9 additions & 5 deletions core/reactor.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(LF_UNTHREADED)
#if defined(LF_SINGLE_THREADED)
/* Runtime infrastructure for the non-threaded version of the C target of Lingua Franca. */

/*************
Expand Down Expand Up @@ -112,7 +112,7 @@ void lf_print_snapshot(environment_t* env) {
* @param reaction The reaction.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*/
void _lf_trigger_reaction(environment_t* env, reaction_t* reaction, int worker_number) {
Expand Down Expand Up @@ -193,7 +193,7 @@ int _lf_do_step(environment_t* env) {

if (!violation) {
// Invoke the reaction function.
_lf_invoke_reaction(env, reaction, 0); // 0 indicates unthreaded.
_lf_invoke_reaction(env, reaction, 0); // 0 indicates single-threaded.

// If the reaction produced outputs, put the resulting triggered
// reactions into the queue.
Expand Down Expand Up @@ -363,7 +363,7 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
environment_t *env;
int num_environments = _lf_get_environments(&env);
lf_assert(num_environments == 1,
"Found %d environments. Only 1 can be used with the unthreaded runtime", num_environments);
"Found %d environments. Only 1 can be used with the single-threaded runtime", num_environments);

LF_PRINT_DEBUG("Initializing.");
initialize_global();
Expand Down Expand Up @@ -396,8 +396,12 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
}
}

/**
* @brief Notify of new event by calling the single-threaded platform API
* @param env Environment in which we are executing.
*/
int lf_notify_of_event(environment_t* env) {
return _lf_unthreaded_notify_of_event();
return _lf_single_threaded_notify_of_event();
}

int lf_critical_section_enter(environment_t* env) {
Expand Down
6 changes: 3 additions & 3 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void lf_set_stp_offset(interval_t offset) {
* @param reaction The reaction.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*/
void _lf_trigger_reaction(environment_t* env, reaction_t* reaction, int worker_number);
Expand Down Expand Up @@ -1335,7 +1335,7 @@ trigger_handle_t _lf_schedule_int(lf_action_base_t* action, interval_t extra_del
*
* @param env Environment in which we are executing.
* @param reaction The reaction that has just executed.
* @param worker The thread number of the worker thread or 0 for unthreaded execution (for tracing).
* @param worker The thread number of the worker thread or 0 for single-threaded execution (for tracing).
*/
void _lf_invoke_reaction(environment_t* env, reaction_t* reaction, int worker) {
assert(env != GLOBAL_ENVIRONMENT);
Expand Down Expand Up @@ -1367,7 +1367,7 @@ void _lf_invoke_reaction(environment_t* env, reaction_t* reaction, int worker) {
* the lock only when it actually inserts something onto the reaction queue.
* @param env Environment in which we are executing.
* @param reaction The reaction that has just executed.
* @param worker The thread number of the worker thread or 0 for unthreaded execution (for tracing).
* @param worker The thread number of the worker thread or 0 for single-threaded execution (for tracing).
*/
void schedule_output_reactions(environment_t *env, reaction_t* reaction, int worker) {
assert(env != GLOBAL_ENVIRONMENT);
Expand Down
2 changes: 1 addition & 1 deletion core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void lf_request_stop() {
* @param reaction The reaction.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*/
void _lf_trigger_reaction(environment_t* env, reaction_t* reaction, int worker_number) {
Expand Down
2 changes: 1 addition & 1 deletion core/threaded/scheduler_GEDF_NP.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void lf_sched_done_with_reaction(size_t worker_number,
* @param reaction The reaction to trigger at the current tag.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*/
void lf_scheduler_trigger_reaction(lf_scheduler_t* scheduler, reaction_t* reaction, int worker_number) {
Expand Down
2 changes: 1 addition & 1 deletion core/threaded/scheduler_GEDF_NP_CI.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void lf_sched_done_with_reaction(size_t worker_number,
* @param reaction The reaction to trigger at the current tag.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*/
void lf_scheduler_trigger_reaction(lf_scheduler_t* scheduler, reaction_t* reaction, int worker_number) {
Expand Down
2 changes: 1 addition & 1 deletion core/threaded/scheduler_NP.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void lf_sched_done_with_reaction(size_t worker_number,
* @param reaction The reaction to trigger at the current tag.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*
*/
Expand Down
2 changes: 1 addition & 1 deletion core/threaded/scheduler_PEDF_NP.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ void lf_sched_done_with_reaction(size_t worker_number, reaction_t* done_reaction
* @param reaction The reaction to trigger at the current tag.
* @param worker_number The 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
* unthreaded C runtime). -1 is used for an anonymous call in a context where a
* 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).
*
*/
Expand Down
12 changes: 6 additions & 6 deletions core/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void start_trace(trace_t* trace) {
trace->_lf_trace_header_written = false;

// Allocate an array of arrays of trace records, one per worker thread plus one
// for the 0 thread (the main thread, or in an unthreaded program, the only
// for the 0 thread (the main thread, or in an single-threaded program, the only
// thread).
trace->_lf_number_of_trace_buffers = _lf_number_of_workers + 1;
trace->_lf_trace_buffer = (trace_record_t**)malloc(sizeof(trace_record_t*) * trace->_lf_number_of_trace_buffers);
Expand Down Expand Up @@ -326,7 +326,7 @@ void tracepoint(
/**
* Trace the start of a reaction execution.
* @param reaction Pointer to the reaction_t struct for the reaction.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
* @param worker The thread number of the worker thread or 0 for single-threaded execution.
*/
void tracepoint_reaction_starts(trace_t* trace, reaction_t* reaction, int worker) {
tracepoint(trace, reaction_starts, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, true);
Expand All @@ -335,7 +335,7 @@ void tracepoint_reaction_starts(trace_t* trace, reaction_t* reaction, int worker
/**
* Trace the end of a reaction execution.
* @param reaction Pointer to the reaction_t struct for the reaction.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
* @param worker The thread number of the worker thread or 0 for single-threaded execution.
*/
void tracepoint_reaction_ends(trace_t* trace, reaction_t* reaction, int worker) {
tracepoint(trace, reaction_ends, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, false);
Expand Down Expand Up @@ -418,15 +418,15 @@ void tracepoint_user_value(void* self, char* description, long long value) {

/**
* Trace the start of a worker waiting for something to change on the event or reaction queue.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
* @param worker The thread number of the worker thread or 0 for single-threaded execution.
*/
void tracepoint_worker_wait_starts(trace_t* trace, int worker) {
tracepoint(trace, worker_wait_starts, NULL, NULL, worker, worker, -1, NULL, NULL, 0, true);
}

/**
* Trace the end of a worker waiting for something to change on the event or reaction queue.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
* @param worker The thread number of the worker thread or 0 for single-threaded execution.
*/
void tracepoint_worker_wait_ends(trace_t* trace, int worker) {
tracepoint(trace, worker_wait_ends, NULL, NULL, worker, worker, -1, NULL, NULL, 0, false);
Expand All @@ -451,7 +451,7 @@ void tracepoint_scheduler_advancing_time_ends(trace_t* trace) {
/**
* Trace the occurrence of a deadline miss.
* @param reaction Pointer to the reaction_t struct for the reaction.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
* @param worker The thread number of the worker thread or 0 for single-threaded execution.
*/
void tracepoint_reaction_deadline_missed(trace_t* trace, reaction_t *reaction, int worker) {
tracepoint(trace, reaction_deadline_missed, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, false);
Expand Down
2 changes: 1 addition & 1 deletion include/core/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ typedef struct environment_t {
int reset_reactions_size;
mode_environment_t* modes;
trace_t* trace;
#ifdef LF_UNTHREADED
#ifdef LF_SINGLE_THREADED
pqueue_t *reaction_q;
#endif
#ifdef LF_THREADED
Expand Down
Loading