Skip to content

Commit

Permalink
Merge pull request #250 from lf-lang/single-threaded
Browse files Browse the repository at this point in the history
Mentions of "unthreaded" replaced with "single-threaded"
  • Loading branch information
lhstrh authored Nov 8, 2023
2 parents d82cf9d + b19fff3 commit d26e285
Show file tree
Hide file tree
Showing 42 changed files with 117 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
unit-tests-single:
uses: ./.github/workflows/unit-tests.yml
with:
cmake-args: '-UNUMBER_OF_WORKERS -DLF_UNTHREADED=1'
cmake-args: '-UNUMBER_OF_WORKERS -DLF_SINGLE_THREADED=1'

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
Expand Down
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ 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)
if(DEFINED LF_SINGLE_THREADED)
add_compile_definitions(LF_SINGLE_THREADED=1)
endif()

set(Test test)
Expand Down
21 changes: 10 additions & 11 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ 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
if(DEFINED LF_THREADED)
# Add sources for either threaded or single-threaded runtime
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)
else()
message(STATUS "Including sources for unthreaded runtime.")
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
target_sources(core PRIVATE ${SINGLE_THREADED_SOURCES})
list(APPEND INFO_SOURCES ${SINGLE_THREADED_SOURCES})
endif()


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -112,9 +112,8 @@ define(FEDERATED_DECENTRALIZED)
define(FEDERATED)
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
20 changes: 10 additions & 10 deletions core/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
#include "lf_types.h"
#include <string.h>
#include "trace.h"
#ifdef LF_THREADED
#if !defined(LF_SINGLE_THREADED)
#include "scheduler.h"
#endif

/**
* @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");
Expand All @@ -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 @@ -126,14 +126,14 @@ 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
}

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/federated/RTI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/platform/arduino_mbed/ConditionWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author{Anirudh Rengarajan <[email protected]>}
*/

#if defined(LF_THREADED)
#if !defined(LF_SINGLE_THREADED)
#include "mbed.h"
#include "MutexWrapper.h"

Expand Down
2 changes: 1 addition & 1 deletion core/platform/arduino_mbed/MutexWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author{Anirudh Rengarajan <[email protected]>}
*/

#if defined(LF_THREADED)
#if !defined(LF_SINGLE_THREADED)
#include "mbed.h"
#include "rtos.h"
using namespace rtos;
Expand Down
2 changes: 1 addition & 1 deletion core/platform/arduino_mbed/ThreadWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author{Anirudh Rengarajan <[email protected]>}
*/

#if defined(LF_THREADED)
#if !defined(LF_SINGLE_THREADED)
#include "mbed.h"
#include "rtos.h"

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_C11_threads_support.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_POSIX_threads_support.c
Original file line number Diff line number Diff line change
@@ -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"

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
4 changes: 2 additions & 2 deletions core/platform/lf_linux_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ 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

#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"
Expand Down
4 changes: 2 additions & 2 deletions core/platform/lf_macos_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ 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

#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"
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
19 changes: 10 additions & 9 deletions core/platform/lf_rp2040_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author{Abhi Gundrala <[email protected]>}
*/

#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"
Expand Down Expand Up @@ -59,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
Expand Down Expand Up @@ -113,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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -205,16 +209,13 @@ 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;
}
#endif //LF_UNTHREADED
#endif // LF_SINGLE_THREADED

#ifdef LF_THREADED
#error "Threading for baremetal RP2040 not supported"
#endif //LF_THREADED

#endif // PLATFORM_RP2040

4 changes: 2 additions & 2 deletions core/platform/lf_windows_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ 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


#if defined(LF_THREADED)
#if !defined(LF_SINGLE_THREADED)
int lf_available_cores() {
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_zephyr_clock_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/platform/lf_zephyr_clock_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions core/platform/lf_zephyr_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ int lf_enable_interrupts_nested() {
return 0;
}

#if defined(LF_THREADED)

#if !defined(LF_SINGLE_THREADED)
#if !defined(LF_ZEPHYR_STACK_SIZE)
#define LF_ZEPHYR_STACK_SIZE LF_ZEPHYR_STACK_SIZE_DEFAULT
#endif
Expand Down
Loading

0 comments on commit d26e285

Please sign in to comment.