From 36685f58aecf63b35e051d434763492e00c6fd32 Mon Sep 17 00:00:00 2001 From: Atharva Patil Date: Thu, 13 Jul 2023 21:29:15 +0900 Subject: [PATCH 1/5] Replaced 'unthreaded' with 'single-threaded' in all variables and comments. --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 4 ++-- core/CMakeLists.txt | 8 ++++---- core/environment.c | 14 +++++++------- core/platform/lf_arduino_support.c | 4 ++-- core/platform/lf_linux_support.c | 2 +- core/platform/lf_macos_support.c | 2 +- core/platform/lf_nrf52_support.c | 2 +- core/platform/lf_os_single_threaded_support.c | 6 +++--- core/platform/lf_windows_support.c | 2 +- core/platform/lf_zephyr_support.c | 2 +- core/reactor.c | 12 ++++++------ core/reactor_common.c | 6 +++--- core/threaded/reactor_threaded.c | 2 +- core/threaded/scheduler_GEDF_NP.c | 2 +- core/threaded/scheduler_GEDF_NP_CI.c | 2 +- core/threaded/scheduler_NP.c | 2 +- core/threaded/scheduler_PEDF_NP.c | 2 +- core/trace.c | 12 ++++++------ include/core/environment.h | 2 +- include/core/platform.h | 12 ++++++------ include/core/reactor.h | 2 +- include/core/threaded/scheduler.h | 2 +- include/core/trace.h | 10 +++++----- 24 files changed, 58 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd78c1471..d15d498e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index c675a3f53..e8f6b36a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 8c6aa919c..420241743 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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}) @@ -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) diff --git a/core/environment.c b/core/environment.c index 4216800dc..2cc0d28e2 100644 --- a/core/environment.c +++ b/core/environment.c @@ -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. @@ -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 } @@ -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); @@ -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); diff --git a/core/platform/lf_arduino_support.c b/core/platform/lf_arduino_support.c index bf1ac9483..57c28d1ec 100644 --- a/core/platform/lf_arduino_support.c +++ b/core/platform/lf_arduino_support.c @@ -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) { @@ -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; } diff --git a/core/platform/lf_linux_support.c b/core/platform/lf_linux_support.c index 3bb5077c8..d9828fc2a 100644 --- a/core/platform/lf_linux_support.c +++ b/core/platform/lf_linux_support.c @@ -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 diff --git a/core/platform/lf_macos_support.c b/core/platform/lf_macos_support.c index 93908a6dd..11b25c65e 100644 --- a/core/platform/lf_macos_support.c +++ b/core/platform/lf_macos_support.c @@ -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 diff --git a/core/platform/lf_nrf52_support.c b/core/platform/lf_nrf52_support.c index 3928b06db..61dcc101b 100644 --- a/core/platform/lf_nrf52_support.c +++ b/core/platform/lf_nrf52_support.c @@ -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; } diff --git a/core/platform/lf_os_single_threaded_support.c b/core/platform/lf_os_single_threaded_support.c index dc4c4e8f5..1306d4c17 100644 --- a/core/platform/lf_os_single_threaded_support.c +++ b/core/platform/lf_os_single_threaded_support.c @@ -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 (marten@berkeley.edu) @@ -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. * @@ -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; } diff --git a/core/platform/lf_windows_support.c b/core/platform/lf_windows_support.c index b1ec9b20a..5a935fa3a 100644 --- a/core/platform/lf_windows_support.c +++ b/core/platform/lf_windows_support.c @@ -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 diff --git a/core/platform/lf_zephyr_support.c b/core/platform/lf_zephyr_support.c index de8e51c23..ffe794e99 100644 --- a/core/platform/lf_zephyr_support.c +++ b/core/platform/lf_zephyr_support.c @@ -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 diff --git a/core/reactor.c b/core/reactor.c index d9e2bbc6e..b5bbc38fe 100644 --- a/core/reactor.c +++ b/core/reactor.c @@ -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. */ /************* @@ -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) { @@ -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. @@ -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(); @@ -397,11 +397,11 @@ int lf_reactor_c_main(int argc, const char* argv[]) { } /** - * @brief Notify of new event by calling the unthreaded platform API + * @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(); } /** diff --git a/core/reactor_common.c b/core/reactor_common.c index 47157752d..cd26da119 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -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); @@ -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); @@ -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); diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index e31bb6f16..8e04ffe04 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -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) { diff --git a/core/threaded/scheduler_GEDF_NP.c b/core/threaded/scheduler_GEDF_NP.c index 36c72851b..6355cf374 100644 --- a/core/threaded/scheduler_GEDF_NP.c +++ b/core/threaded/scheduler_GEDF_NP.c @@ -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) { diff --git a/core/threaded/scheduler_GEDF_NP_CI.c b/core/threaded/scheduler_GEDF_NP_CI.c index 151de02a8..77647d947 100644 --- a/core/threaded/scheduler_GEDF_NP_CI.c +++ b/core/threaded/scheduler_GEDF_NP_CI.c @@ -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) { diff --git a/core/threaded/scheduler_NP.c b/core/threaded/scheduler_NP.c index 8b1c3feef..1895772d8 100644 --- a/core/threaded/scheduler_NP.c +++ b/core/threaded/scheduler_NP.c @@ -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). * */ diff --git a/core/threaded/scheduler_PEDF_NP.c b/core/threaded/scheduler_PEDF_NP.c index 634fafd40..8d69ef08a 100644 --- a/core/threaded/scheduler_PEDF_NP.c +++ b/core/threaded/scheduler_PEDF_NP.c @@ -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). * */ diff --git a/core/trace.c b/core/trace.c index 1e9703c09..1839e8f84 100644 --- a/core/trace.c +++ b/core/trace.c @@ -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); @@ -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); @@ -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); @@ -418,7 +418,7 @@ 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); @@ -426,7 +426,7 @@ void tracepoint_worker_wait_starts(trace_t* trace, int worker) { /** * 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); @@ -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); diff --git a/include/core/environment.h b/include/core/environment.h index ed93b72d2..b4fcc718e 100644 --- a/include/core/environment.h +++ b/include/core/environment.h @@ -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 diff --git a/include/core/platform.h b/include/core/platform.h index 283b76753..fc3847815 100644 --- a/include/core/platform.h +++ b/include/core/platform.h @@ -36,8 +36,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef PLATFORM_H #define PLATFORM_H -#if defined(LF_THREADED) && defined(LF_UNTHREADED) -#error LF_UNTHREADED and LF_THREADED runtime requested +#if defined(LF_THREADED) && defined(LF_SINGLE_THREADED) +#error LF_SINGLE_THREADED and LF_THREADED runtime requested #endif #ifdef __cplusplus @@ -85,9 +85,9 @@ typedef struct environment_t environment_t; #define LF_TIMEOUT 1 -// To support the unthreaded runtime, we need the following functions. They +// To support the single-threaded runtime, we need the following functions. They // are not required by the threaded runtime and is thus hidden behind a #ifdef. -#if defined (LF_UNTHREADED) +#if defined (LF_SINGLE_THREADED) /** * @brief Disable interrupts with support for nested calls * @@ -102,11 +102,11 @@ typedef struct environment_t environment_t; int lf_enable_interrupts_nested(); /** - * @brief Notify sleeping unthreaded context of new event + * @brief Notify sleeping single-threaded context of new event * * @return int */ - int _lf_unthreaded_notify_of_event(); + int _lf_single_threaded_notify_of_event(); #endif diff --git a/include/core/reactor.h b/include/core/reactor.h index 87ba8b18f..34cc3173e 100644 --- a/include/core/reactor.h +++ b/include/core/reactor.h @@ -543,7 +543,7 @@ void _lf_create_environments(); /** - * These functions must be implemented by both threaded and unthreaded + * These functions must be implemented by both threaded and single-threaded * runtime. Should be routed to appropriate API calls in platform.h */ diff --git a/include/core/threaded/scheduler.h b/include/core/threaded/scheduler.h index d83307d8c..ab4bec48e 100644 --- a/include/core/threaded/scheduler.h +++ b/include/core/threaded/scheduler.h @@ -115,7 +115,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). * */ diff --git a/include/core/trace.h b/include/core/trace.h index 72e2d466a..357f22b11 100644 --- a/include/core/trace.h +++ b/include/core/trace.h @@ -348,7 +348,7 @@ void tracepoint( * Trace the start of a reaction execution. * @param env The environment in which we are executing * @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); @@ -356,7 +356,7 @@ void tracepoint_reaction_starts(trace_t* trace, reaction_t* reaction, int worker * Trace the end of a reaction execution. * @param env The environment in which we are executing * @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); @@ -397,14 +397,14 @@ void tracepoint_user_value(void* self, char* description, long long value); /** * Trace the start of a worker waiting for something to change on the reaction queue. * @param env The environment in which we are executing - * @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); /** * Trace the end of a worker waiting for something to change on reaction queue. * @param env The environment in which we are executing - * @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); @@ -426,7 +426,7 @@ void tracepoint_scheduler_advancing_time_ends(trace_t* trace); * Trace the occurence of a deadline miss. * @param env The environment in which we are executing * @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); From 1bf82e60619567d7e8d647a6cbef26aad3d48dac Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Mon, 6 Nov 2023 18:23:20 +0100 Subject: [PATCH 2/5] Use only LF_SINGLE_THREADED --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 4 +--- core/CMakeLists.txt | 15 +++++++-------- core/environment.c | 6 +++--- core/federated/RTI/CMakeLists.txt | 4 ++-- core/platform/arduino_mbed/ConditionWrapper.cpp | 2 +- core/platform/arduino_mbed/MutexWrapper.cpp | 2 +- core/platform/arduino_mbed/ThreadWrapper.cpp | 2 +- core/platform/lf_C11_threads_support.c | 2 +- core/platform/lf_POSIX_threads_support.c | 2 +- core/platform/lf_linux_support.c | 2 +- core/platform/lf_macos_support.c | 2 +- core/platform/lf_rp2040_support.c | 9 +++++---- core/platform/lf_windows_support.c | 2 +- core/platform/lf_zephyr_support.c | 2 +- core/reactor_common.c | 8 ++++---- core/threaded/reactor_threaded.c | 2 +- core/threaded/scheduler_NP.c | 4 ++-- core/threaded/scheduler_sync_tag_advance.c | 2 +- core/utils/semaphore.c | 2 +- include/core/environment.h | 11 +++++------ include/core/lf_types.h | 4 ++-- include/core/platform.h | 14 ++------------ include/core/platform/lf_arduino_support.h | 4 ++-- include/core/platform/lf_linux_support.h | 2 +- include/core/platform/lf_macos_support.h | 2 +- include/core/platform/lf_rp2040_support.h | 4 ---- include/core/platform/lf_windows_support.h | 2 +- include/core/platform/lf_zephyr_support.h | 4 ++-- 29 files changed, 53 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0793508c5..76ea8c278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: unit-tests-multi: uses: ./.github/workflows/unit-tests.yml with: - cmake-args: '-DNUMBER_OF_WORKERS=4 -DLF_THREADED=1' + cmake-args: '-DNUMBER_OF_WORKERS=4 -ULF_SINGLE_THREADED' build-rti: uses: ./.github/workflows/build-rti.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index e8f6b36a8..9eadfeda2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,7 @@ endif() # 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() +if(DEFINED LF_SINGLE_THREADED) add_compile_definitions(LF_SINGLE_THREADED=1) endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 9975ab4a3..16bf0e616 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -21,16 +21,16 @@ if (DEFINED FEDERATED) endif() # 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() +if(DEFINED LF_SINGLE_THREADED) 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}) +else() + message(STATUS "Including sources for threaded runtime with \ +${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \ +tracing=${LF_TRACE}.") + include(threaded/CMakeLists.txt) endif() @@ -75,7 +75,7 @@ if(DEFINED _LF_CLOCK_SYNC_ON) endif() # Link with thread library, unless if we are targeting the Zephyr RTOS -if(DEFINED LF_THREADED OR DEFINED LF_TRACE) +if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr") find_package(Threads REQUIRED) target_link_libraries(core PUBLIC Threads::Threads) @@ -112,7 +112,6 @@ define(FEDERATED_DECENTRALIZED) define(FEDERATED) define(FEDERATED_AUTHENTICATED) define(LF_REACTION_GRAPH_BREADTH) -define(LF_THREADED) define(LF_TRACE) define(LF_SINGLE_THREADED) define(LOG_LEVEL) diff --git a/core/environment.c b/core/environment.c index 2cc0d28e2..4ca79c11e 100644 --- a/core/environment.c +++ b/core/environment.c @@ -34,7 +34,7 @@ #include "lf_types.h" #include #include "trace.h" -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) #include "scheduler.h" #endif @@ -42,7 +42,7 @@ * @brief Initialize the threaded part of the environment struct. */ static void environment_init_threaded(environment_t* env, int num_workers) { -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) env->num_workers = num_workers; env->thread_ids = (lf_thread_t*)calloc(num_workers, sizeof(lf_thread_t)); lf_assert(env->thread_ids != NULL, "Out of memory"); @@ -126,7 +126,7 @@ void environment_init_tags( environment_t *env, instant_t start_time, interval_t } static void environment_free_threaded(environment_t* env) { -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) free(env->thread_ids); lf_sched_free(env->scheduler); #endif diff --git a/core/federated/RTI/CMakeLists.txt b/core/federated/RTI/CMakeLists.txt index c43dd70f3..b0fb5a326 100644 --- a/core/federated/RTI/CMakeLists.txt +++ b/core/federated/RTI/CMakeLists.txt @@ -79,8 +79,8 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG) target_compile_definitions(RTI PUBLIC LOG_LEVEL=4) ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG) -# Set LF_THREADING to get the threaded support and FEDERATED to get federated compilation support -target_compile_definitions(RTI PUBLIC LF_THREADED=1 FEDERATED=1) +# Set FEDERATED to get federated compilation support +target_compile_definitions(RTI PUBLIC FEDERATED=1) target_compile_definitions(RTI PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME}) # Set RTI Tracing diff --git a/core/platform/arduino_mbed/ConditionWrapper.cpp b/core/platform/arduino_mbed/ConditionWrapper.cpp index 1e2a8f4ed..6fe3e4422 100644 --- a/core/platform/arduino_mbed/ConditionWrapper.cpp +++ b/core/platform/arduino_mbed/ConditionWrapper.cpp @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Anirudh Rengarajan } */ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) #include "mbed.h" #include "MutexWrapper.h" diff --git a/core/platform/arduino_mbed/MutexWrapper.cpp b/core/platform/arduino_mbed/MutexWrapper.cpp index fa507e31b..3f3165326 100644 --- a/core/platform/arduino_mbed/MutexWrapper.cpp +++ b/core/platform/arduino_mbed/MutexWrapper.cpp @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Anirudh Rengarajan } */ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) #include "mbed.h" #include "rtos.h" using namespace rtos; diff --git a/core/platform/arduino_mbed/ThreadWrapper.cpp b/core/platform/arduino_mbed/ThreadWrapper.cpp index 2b7824606..eaa19ae1e 100644 --- a/core/platform/arduino_mbed/ThreadWrapper.cpp +++ b/core/platform/arduino_mbed/ThreadWrapper.cpp @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Anirudh Rengarajan } */ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) #include "mbed.h" #include "rtos.h" diff --git a/core/platform/lf_C11_threads_support.c b/core/platform/lf_C11_threads_support.c index c0862f742..de3320dd0 100644 --- a/core/platform/lf_C11_threads_support.c +++ b/core/platform/lf_C11_threads_support.c @@ -1,4 +1,4 @@ -#if defined(LF_THREADED) && !defined(PLATFORM_ARDUINO) +#if !defined(LF_SINGLE_THREADED) && !defined(PLATFORM_ARDUINO) #include "platform.h" #include "lf_C11_threads_support.h" diff --git a/core/platform/lf_POSIX_threads_support.c b/core/platform/lf_POSIX_threads_support.c index 180cde8cd..8b505acb5 100644 --- a/core/platform/lf_POSIX_threads_support.c +++ b/core/platform/lf_POSIX_threads_support.c @@ -1,4 +1,4 @@ -#if defined(LF_THREADED) && !defined(PLATFORM_ARDUINO) +#if !defined(LF_SINGLE_THREADED) && !defined(PLATFORM_ARDUINO) #include "platform.h" #include "lf_POSIX_threads_support.h" diff --git a/core/platform/lf_linux_support.c b/core/platform/lf_linux_support.c index d9828fc2a..046415df6 100644 --- a/core/platform/lf_linux_support.c +++ b/core/platform/lf_linux_support.c @@ -43,7 +43,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "lf_os_single_threaded_support.c" #endif -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) // (Not C++11 or later) or no threads support #include "lf_POSIX_threads_support.c" diff --git a/core/platform/lf_macos_support.c b/core/platform/lf_macos_support.c index 11b25c65e..fcc958c8a 100644 --- a/core/platform/lf_macos_support.c +++ b/core/platform/lf_macos_support.c @@ -39,7 +39,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "lf_os_single_threaded_support.c" #endif -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) // (Not C++11 or later) or no threads support #include "lf_POSIX_threads_support.c" diff --git a/core/platform/lf_rp2040_support.c b/core/platform/lf_rp2040_support.c index 8cbc0985e..dbb391133 100644 --- a/core/platform/lf_rp2040_support.c +++ b/core/platform/lf_rp2040_support.c @@ -31,6 +31,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Abhi Gundrala } */ +#if !defined(LF_SINGLE_THREADED) +#error "Only the single-threaded runtime has support for RP2040" +#endif + #include "lf_rp2040_support.h" #include "platform.h" #include "utils/util.h" @@ -145,7 +149,7 @@ int _lf_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup_ti return ret_code; } -#ifdef LF_UNTHREADED +#if defined(LF_SINGLE_THREADED) /** * The single thread RP2040 platform support treats second core * routines similar to external interrupt routine threads. @@ -212,9 +216,6 @@ int _lf_unthreaded_notify_of_event() { } #endif //LF_UNTHREADED -#ifdef LF_THREADED -#error "Threading for baremetal RP2040 not supported" -#endif //LF_THREADED #endif // PLATFORM_RP2040 diff --git a/core/platform/lf_windows_support.c b/core/platform/lf_windows_support.c index 5a935fa3a..f38828505 100644 --- a/core/platform/lf_windows_support.c +++ b/core/platform/lf_windows_support.c @@ -163,7 +163,7 @@ int lf_nanosleep(interval_t sleep_duration) { #endif -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) int lf_available_cores() { SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); diff --git a/core/platform/lf_zephyr_support.c b/core/platform/lf_zephyr_support.c index cbd2f5b09..1e10020b6 100644 --- a/core/platform/lf_zephyr_support.c +++ b/core/platform/lf_zephyr_support.c @@ -74,7 +74,7 @@ int lf_enable_interrupts_nested() { return 0; } -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) #if !defined(LF_ZEPHYR_STACK_SIZE) #define LF_ZEPHYR_STACK_SIZE LF_ZEPHYR_STACK_SIZE_DEFAULT #endif diff --git a/core/reactor_common.c b/core/reactor_common.c index 3be5faadb..5422d1453 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -61,7 +61,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "hashset/hashset_itr.h" #include "environment.h" -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) #include "watchdog.h" // Code generated global variables. @@ -1339,7 +1339,7 @@ trigger_handle_t _lf_schedule_int(lf_action_base_t* action, interval_t extra_del void _lf_invoke_reaction(environment_t* env, reaction_t* reaction, int worker) { assert(env != GLOBAL_ENVIRONMENT); -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) if (((self_base_t*) reaction->self)->reactor_mutex != NULL) { lf_mutex_lock((lf_mutex_t*)((self_base_t*)reaction->self)->reactor_mutex); } @@ -1352,7 +1352,7 @@ void _lf_invoke_reaction(environment_t* env, reaction_t* reaction, int worker) { tracepoint_reaction_ends(env->trace, reaction, worker); -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) if (((self_base_t*) reaction->self)->reactor_mutex != NULL) { lf_mutex_unlock((lf_mutex_t*)((self_base_t*)reaction->self)->reactor_mutex); } @@ -1796,7 +1796,7 @@ void termination(void) { lf_print_warning("Memory allocated for tokens has not been freed!"); lf_print_warning("Number of unfreed tokens: %d.", _lf_count_token_allocations); } -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) for (int i = 0; i < _lf_watchdog_count; i++) { if (_lf_watchdogs[i].base->reactor_mutex != NULL) { free(_lf_watchdogs[i].base->reactor_mutex); diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index c610ecffe..61e844275 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -30,7 +30,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Marten Lohstroh } * @author{Soroush Bateni } */ -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #ifndef NUMBER_OF_WORKERS #define NUMBER_OF_WORKERS 1 #endif // NUMBER_OF_WORKERS diff --git a/core/threaded/scheduler_NP.c b/core/threaded/scheduler_NP.c index a3c219b5a..a9310aa2f 100644 --- a/core/threaded/scheduler_NP.c +++ b/core/threaded/scheduler_NP.c @@ -1,4 +1,4 @@ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) /* Non-preemptive scheduler for the threaded runtime of the C target of Lingua Franca. */ @@ -37,7 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @author{Marten Lohstroh } */ #include "lf_types.h" -#if SCHEDULER == SCHED_NP || (!defined(SCHEDULER) && defined(LF_THREADED)) +#if SCHEDULER == SCHED_NP || !defined(SCHEDULER) #ifndef NUMBER_OF_WORKERS #define NUMBER_OF_WORKERS 1 #endif // NUMBER_OF_WORKERS diff --git a/core/threaded/scheduler_sync_tag_advance.c b/core/threaded/scheduler_sync_tag_advance.c index cdaff6d21..4c68a623a 100644 --- a/core/threaded/scheduler_sync_tag_advance.c +++ b/core/threaded/scheduler_sync_tag_advance.c @@ -1,4 +1,4 @@ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) /************* Copyright (c) 2022, The University of Texas at Dallas. Copyright (c) 2022, The University of California at Berkeley. diff --git a/core/utils/semaphore.c b/core/utils/semaphore.c index 87ce94443..244594762 100644 --- a/core/utils/semaphore.c +++ b/core/utils/semaphore.c @@ -1,4 +1,4 @@ -#if defined(LF_THREADED) +#if !defined(LF_SINGLE_THREADED) /* Semaphore utility for reactor C. */ /************* diff --git a/include/core/environment.h b/include/core/environment.h index b4fcc718e..db97d4f05 100644 --- a/include/core/environment.h +++ b/include/core/environment.h @@ -88,10 +88,9 @@ typedef struct environment_t { int reset_reactions_size; mode_environment_t* modes; trace_t* trace; -#ifdef LF_SINGLE_THREADED +#if defined(LF_SINGLE_THREADED) pqueue_t *reaction_q; -#endif -#ifdef LF_THREADED +#else int num_workers; lf_thread_t* thread_ids; lf_mutex_t mutex; @@ -99,14 +98,14 @@ typedef struct environment_t { lf_scheduler_t* scheduler; _lf_tag_advancement_barrier barrier; lf_cond_t global_tag_barrier_requestors_reached_zero; -#endif // LF_THREADED -#ifdef FEDERATED +#endif // LF_SINGLE_THREADED +#if defined(FEDERATED) tag_t** _lf_intended_tag_fields; int _lf_intended_tag_fields_size; #endif // FEDERATED } environment_t; -#ifdef MODAL_REACTORS +#if defined(MODAL_REACTORS) struct mode_environment_t { uint8_t triggered_reactions_request; reactor_mode_state_t** modal_reactor_states; diff --git a/include/core/lf_types.h b/include/core/lf_types.h index 6b7ad34d2..a48d445fc 100644 --- a/include/core/lf_types.h +++ b/include/core/lf_types.h @@ -298,11 +298,11 @@ typedef struct self_base_t { struct allocation_record_t *allocations; struct reaction_t *executing_reaction; // The currently executing reaction of the reactor. environment_t * environment; -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t. // It is not declared as such to avoid a dependence on platform.h. #endif -#ifdef MODAL_REACTORS +#if defined(MODAL_REACTORS) reactor_mode_state_t _lf__mode_state; // The current mode (for modal models). #endif } self_base_t; diff --git a/include/core/platform.h b/include/core/platform.h index 470075dfb..8decedd74 100644 --- a/include/core/platform.h +++ b/include/core/platform.h @@ -36,10 +36,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef PLATFORM_H #define PLATFORM_H -#if defined(LF_THREADED) && defined(LF_SINGLE_THREADED) -#error LF_SINGLE_THREADED and LF_THREADED runtime requested -#endif - #ifdef __cplusplus extern "C" { #endif @@ -98,16 +94,13 @@ int lf_critical_section_exit(environment_t* env); #error "Platform not supported" #endif -#if !defined(LF_THREADED) - typedef void lf_mutex_t; -#endif - #define LF_TIMEOUT 1 // To support the single-threaded runtime, we need the following functions. They // are not required by the threaded runtime and is thus hidden behind a #ifdef. #if defined (LF_SINGLE_THREADED) + typedef void lf_mutex_t; /** * @brief Disable interrupts with support for nested calls * @@ -127,12 +120,9 @@ int lf_critical_section_exit(environment_t* env); * @return int */ int _lf_single_threaded_notify_of_event(); -#endif - - +#else // For platforms with threading support, the following functions // abstract the API so that the LF runtime remains portable. -#if defined LF_THREADED /** diff --git a/include/core/platform/lf_arduino_support.h b/include/core/platform/lf_arduino_support.h index 9685090c1..ad9adde1c 100644 --- a/include/core/platform/lf_arduino_support.h +++ b/include/core/platform/lf_arduino_support.h @@ -112,14 +112,14 @@ struct timespec { #endif #endif -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) #warning "Threaded support on Arduino is still experimental" typedef void* lf_mutex_t; typedef void* lf_cond_t; typedef void* lf_thread_t; -#endif // LF_THREADED +#endif // !LF_SNIGLE_THREADED #define PRINTF_TIME "%" PRIu32 #define PRINTF_MICROSTEP "%" PRIu32 diff --git a/include/core/platform/lf_linux_support.h b/include/core/platform/lf_linux_support.h index 021b236db..17b01f134 100644 --- a/include/core/platform/lf_linux_support.h +++ b/include/core/platform/lf_linux_support.h @@ -39,7 +39,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Use 64-bit times and 32-bit unsigned microsteps #include "lf_tag_64_32.h" -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) // (Not C++11 or later) or no threads support #include "lf_POSIX_threads_support.h" diff --git a/include/core/platform/lf_macos_support.h b/include/core/platform/lf_macos_support.h index a769f6122..4aad2d19d 100644 --- a/include/core/platform/lf_macos_support.h +++ b/include/core/platform/lf_macos_support.h @@ -41,7 +41,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // The underlying physical clock for MacOS #define _LF_CLOCK CLOCK_MONOTONIC -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) // (Not C++11 or later) or no threads support #include "lf_POSIX_threads_support.h" diff --git a/include/core/platform/lf_rp2040_support.h b/include/core/platform/lf_rp2040_support.h index b522d9e65..1b23e3a2e 100644 --- a/include/core/platform/lf_rp2040_support.h +++ b/include/core/platform/lf_rp2040_support.h @@ -20,8 +20,4 @@ #define LF_TIME_BUFFER_LENGTH 80 #define _LF_TIMEOUT 1 -#ifdef LF_THREADED -#error "Threading for baremetal RP2040 not supported" -#endif // LF_THREADED - #endif // LF_PICO_SUPPORT_H diff --git a/include/core/platform/lf_windows_support.h b/include/core/platform/lf_windows_support.h index ee84d0973..b32e03bfa 100644 --- a/include/core/platform/lf_windows_support.h +++ b/include/core/platform/lf_windows_support.h @@ -43,7 +43,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // For fixed-width integral types #include -#if defined LF_THREADED +#if !defined LF_SINGLE_THREADED #if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) /** * On Windows, one could use both a mutex or diff --git a/include/core/platform/lf_zephyr_support.h b/include/core/platform/lf_zephyr_support.h index d1f132323..0221010dc 100644 --- a/include/core/platform/lf_zephyr_support.h +++ b/include/core/platform/lf_zephyr_support.h @@ -41,7 +41,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #define NO_TTY -#ifdef LF_THREADED +#if !defined(LF_SINGLE_THREADED) typedef struct k_mutex lf_mutex_t; typedef struct { @@ -73,7 +73,7 @@ bool _zephyr_bool_compare_and_swap(bool *ptr, bool value, bool newval); */ int _zephyr_val_compare_and_swap(int *ptr, int value, int newval); -#endif // LF_THREADED +#endif // !LF_SINGLE_THREADED From 07c3c40b3134480fff8b01da8927e4e0cc79d1d1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 6 Nov 2023 21:10:52 +0100 Subject: [PATCH 3/5] More unthreaded -> single_threaded --- core/platform/lf_rp2040_support.c | 8 ++++---- core/platform/lf_zephyr_clock_counter.c | 2 +- core/platform/lf_zephyr_clock_kernel.c | 2 +- include/core/platform.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/platform/lf_rp2040_support.c b/core/platform/lf_rp2040_support.c index dbb391133..51087538e 100644 --- a/core/platform/lf_rp2040_support.c +++ b/core/platform/lf_rp2040_support.c @@ -63,7 +63,7 @@ static uint32_t _lf_num_nested_crit_sec = 0; /** * Initialize basic runtime infrastructure and - * synchronization structs for an unthreaded runtime. + * synchronization structs for an single-threaded runtime. */ void _lf_initialize_clock(void) { // init stdio lib @@ -117,8 +117,8 @@ int lf_sleep(interval_t sleep_duration) { * by the argument or return early if the binary * _lf_sem_irq_event semaphore is released before the target time. * - * The semaphore is released using the _lf_unthreaded_notify_of_event - * which is called by lf_schedule in the unthreaded runtime for physical actions. + * The semaphore is released using the _lf_single_threaded_notify_of_event + * which is called by lf_schedule in the single_threaded runtime for physical actions. * * @param env pointer to environment struct this runs in. * @param wakeup_time time in nanoseconds since boot to sleep until. @@ -209,7 +209,7 @@ int lf_enable_interrupts_nested() { * * @return error code or 0 on success */ -int _lf_unthreaded_notify_of_event() { +int _lf_single_threaded_notify_of_event() { // notify main sleep loop of event sem_release(&_lf_sem_irq_event); return 0; diff --git a/core/platform/lf_zephyr_clock_counter.c b/core/platform/lf_zephyr_clock_counter.c index e292e2715..f6110b19b 100644 --- a/core/platform/lf_zephyr_clock_counter.c +++ b/core/platform/lf_zephyr_clock_counter.c @@ -210,7 +210,7 @@ int _lf_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup) { /** * We notify of async events by setting the flag and giving the semaphore. */ -int _lf_unthreaded_notify_of_event() { +int _lf_single_threaded_notify_of_event() { async_event = true; k_sem_give(&semaphore); return 0; diff --git a/core/platform/lf_zephyr_clock_kernel.c b/core/platform/lf_zephyr_clock_kernel.c index fae932742..281cfe3db 100644 --- a/core/platform/lf_zephyr_clock_kernel.c +++ b/core/platform/lf_zephyr_clock_kernel.c @@ -94,7 +94,7 @@ int _lf_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup) { * Asynchronous events are notified by setting a flag which breaks the sleeping * thread out of the busy-wait. */ -int _lf_unthreaded_notify_of_event() { +int _lf_single_threaded_notify_of_event() { async_event = true; return 0; } diff --git a/include/core/platform.h b/include/core/platform.h index 8decedd74..defc67ecf 100644 --- a/include/core/platform.h +++ b/include/core/platform.h @@ -47,7 +47,7 @@ extern "C" { typedef struct environment_t environment_t; /** - * @brief Notify of new event by calling the unthreaded platform API + * @brief Notify of new event. * @param env Environment in which we are executing. */ int lf_notify_of_event(environment_t* env); From 02a13f0d436b1618c2f923597319113fb1a28732 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 6 Nov 2023 22:13:03 +0100 Subject: [PATCH 4/5] Update lf-ref --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index c8ed1b5d2..5fde102e7 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -decentralized-small-delay-bugfix +single-threaded From 93438c629239355c491c8a8a52ee75f90e81d0e7 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 7 Nov 2023 15:23:23 +0100 Subject: [PATCH 5/5] More renamings --- core/platform/lf_rp2040_support.c | 2 +- util/tracing/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/platform/lf_rp2040_support.c b/core/platform/lf_rp2040_support.c index 51087538e..045c6d6d9 100644 --- a/core/platform/lf_rp2040_support.c +++ b/core/platform/lf_rp2040_support.c @@ -214,7 +214,7 @@ int _lf_single_threaded_notify_of_event() { sem_release(&_lf_sem_irq_event); return 0; } -#endif //LF_UNTHREADED +#endif // LF_SINGLE_THREADED #endif // PLATFORM_RP2040 diff --git a/util/tracing/Makefile b/util/tracing/Makefile index 9700ac82f..b20292d00 100644 --- a/util/tracing/Makefile +++ b/util/tracing/Makefile @@ -8,7 +8,7 @@ CFLAGS= -I$(REACTOR_C)/include/core/ \ -I$(REACTOR_C)/include/core/modal_models \ -I$(REACTOR_C)/include/core/platform \ -I$(REACTOR_C)/include/core/utils \ - -DLF_UNTHREADED=1 \ + -DLF_SINGLE_THREADED=1 \ -Wall DEPS= LIBS=-lcurl