Skip to content

Commit c5e5c80

Browse files
committed
Merge branch 'main' into semaphore-file-rename
2 parents 9dec011 + e11540e commit c5e5c80

File tree

10 files changed

+108
-78
lines changed

10 files changed

+108
-78
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ endif()
2424

2525
set(Test test)
2626
set(Lib lib)
27-
set(CoreLib core)
27+
set(CoreLibPath core)
28+
set(CoreLib reactor-c)
2829
set(PlatformLib platform)
2930

3031
include_directories(${CMAKE_SOURCE_DIR}/include)
@@ -40,6 +41,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/api)
4041
enable_testing()
4142
add_subdirectory(${Test})
4243
add_subdirectory(${Lib})
43-
add_subdirectory(${CoreLib})
44+
add_subdirectory(${CoreLibPath})
4445

4546
include(test/Tests.cmake)

core/CMakeLists.txt

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ if (DEFINED LF_TRACE)
99
list(APPEND GENERAL_SOURCES trace.c)
1010
endif()
1111

12-
# Store all sources used to build the reactor-c lib in INFO_SOURCES
13-
list(APPEND INFO_SOURCES ${GENERAL_SOURCES})
14-
15-
# Create the core library
16-
add_library(core ${GENERAL_SOURCES})
12+
# Add the general sources to the list of REACTORC_SOURCES
13+
list(APPEND REACTORC_SOURCES ${GENERAL_SOURCES})
1714

1815
# Add sources for either threaded or single-threaded runtime
1916
if (DEFINED FEDERATED)
@@ -25,8 +22,7 @@ endif()
2522
if(DEFINED LF_SINGLE_THREADED)
2623
message(STATUS "Including sources for single-threaded runtime.")
2724
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
28-
target_sources(core PRIVATE ${SINGLE_THREADED_SOURCES})
29-
list(APPEND INFO_SOURCES ${SINGLE_THREADED_SOURCES})
25+
list(APPEND REACTORC_SOURCES ${SINGLE_THREADED_SOURCES})
3026
else()
3127
message(STATUS "Including sources for threaded runtime with \
3228
${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \
@@ -44,20 +40,33 @@ include(utils/CMakeLists.txt)
4440
include(modal_models/CMakeLists.txt)
4541
include(platform/CMakeLists.txt)
4642

47-
4843
# Print sources used for compilation
49-
list(JOIN INFO_SOURCES ", " PRINTABLE_SOURCE_LIST)
44+
list(JOIN REACTORC_SOURCES ", " PRINTABLE_SOURCE_LIST)
5045
message(STATUS "Including the following sources: " ${PRINTABLE_SOURCE_LIST})
5146

52-
target_include_directories(core PUBLIC ../include)
53-
target_include_directories(core PUBLIC ../include/core)
54-
target_include_directories(core PUBLIC ../include/core/federated)
55-
target_include_directories(core PUBLIC ../include/core/federated/network)
56-
target_include_directories(core PUBLIC ../include/core/platform)
57-
target_include_directories(core PUBLIC ../include/core/modal_models)
58-
target_include_directories(core PUBLIC ../include/core/threaded)
59-
target_include_directories(core PUBLIC ../include/core/utils)
60-
target_include_directories(core PUBLIC federated/RTI/)
47+
# Create the reactor-c library. If we are targeting Zephyr we have to use the
48+
# Zephyr Cmake extension to create the library and add the sources.
49+
if(PLATFORM_ZEPHYR)
50+
message("--- Building Zephyr library")
51+
zephyr_library_named(reactor-c)
52+
zephyr_library_sources(${REACTORC_SOURCES})
53+
zephyr_library_link_libraries(kernel)
54+
else()
55+
add_library(reactor-c ${REACTORC_SOURCES})
56+
endif()
57+
58+
# Apply compile definitions to the reactor-c library.
59+
target_compile_definitions(reactor-c PUBLIC ${REACTORC_COMPILE_DEFS})
60+
61+
target_include_directories(reactor-c PUBLIC ../include)
62+
target_include_directories(reactor-c PUBLIC ../include/core)
63+
target_include_directories(reactor-c PUBLIC ../include/core/federated)
64+
target_include_directories(reactor-c PUBLIC ../include/core/federated/network)
65+
target_include_directories(reactor-c PUBLIC ../include/core/platform)
66+
target_include_directories(reactor-c PUBLIC ../include/core/modal_models)
67+
target_include_directories(reactor-c PUBLIC ../include/core/threaded)
68+
target_include_directories(reactor-c PUBLIC ../include/core/utils)
69+
target_include_directories(reactor-c PUBLIC federated/RTI/)
6170

6271
if (APPLE)
6372
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
@@ -72,38 +81,38 @@ if(DEFINED FEDERATED_AUTHENTICATED)
7281
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
7382
endif()
7483
find_package(OpenSSL REQUIRED)
75-
target_link_libraries(core PUBLIC OpenSSL::SSL)
84+
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
7685
endif()
7786

7887
if(DEFINED _LF_CLOCK_SYNC_ON)
7988
find_library(MATH_LIBRARY m)
8089
if(MATH_LIBRARY)
81-
target_link_libraries(core PUBLIC ${MATH_LIBRARY})
90+
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
8291
endif()
8392
endif()
8493

85-
# Link with thread library, unless if we are targeting the Zephyr RTOS
94+
# Link with thread library, unless we are on the Zephyr platform.
8695
if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE)
87-
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
96+
if (NOT PLATFORM_ZEPHYR)
8897
find_package(Threads REQUIRED)
89-
target_link_libraries(core PUBLIC Threads::Threads)
98+
target_link_libraries(reactor-c PUBLIC Threads::Threads)
9099
endif()
91100
endif()
92101

93102
# Macro for translating a command-line argument into compile definition for
94-
# core lib
103+
# reactor-c lib
95104
macro(define X)
96105
if(DEFINED ${X})
97106
message(STATUS ${X}=${${X}})
98-
target_compile_definitions(core PUBLIC ${X}=${${X}})
107+
target_compile_definitions(reactor-c PUBLIC ${X}=${${X}})
99108
endif(DEFINED ${X})
100109
endmacro()
101110

102111
# FIXME: May want these to be application dependent, hence passed as
103112
# parameters to Cmake.
104-
target_compile_definitions(core PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
105-
target_compile_definitions(core PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
106-
target_compile_definitions(core PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
113+
target_compile_definitions(reactor-c PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
114+
target_compile_definitions(reactor-c PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
115+
target_compile_definitions(reactor-c PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
107116

108117
# Search and apply all possible compile definitions
109118
message(STATUS "Applying preprocessor definitions...")

core/environment.c

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
9090
modes->modal_reactor_states_size = num_modes;
9191
modes->triggered_reactions_request = 0;
9292

93-
modes->state_resets = (mode_state_variable_reset_data_t *) calloc(num_state_resets, sizeof(mode_state_variable_reset_data_t));
94-
LF_ASSERT(modes->state_resets, "Out of memory");
9593
modes->state_resets_size = num_state_resets;
94+
if (modes->state_resets_size > 0) {
95+
modes->state_resets = (mode_state_variable_reset_data_t *) calloc(modes->state_resets_size, sizeof(mode_state_variable_reset_data_t));
96+
LF_ASSERT(modes->state_resets, "Out of memory");
97+
} else {
98+
modes->state_resets = NULL;
99+
}
96100

97101
env->modes = modes;
98102

@@ -107,9 +111,13 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
107111
*/
108112
static void environment_init_federated(environment_t* env, int num_is_present_fields) {
109113
#ifdef FEDERATED_DECENTRALIZED
110-
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
111-
LF_ASSERT(env->_lf_intended_tag_fields, "Out of memory");
112-
env->_lf_intended_tag_fields_size = num_is_present_fields;
114+
if (num_is_present_fields > 0) {
115+
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
116+
LF_ASSERT(env->_lf_intended_tag_fields, "Out of memory");
117+
env->_lf_intended_tag_fields_size = num_is_present_fields;
118+
} else {
119+
env->_lf_intended_tag_fields_size = NULL;
120+
}
113121
#endif
114122
}
115123

@@ -197,29 +205,49 @@ int environment_init(
197205
env->stop_tag = FOREVER_TAG;
198206

199207
env->timer_triggers_size=num_timers;
200-
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
201-
LF_ASSERT(env->timer_triggers, "Out of memory");
208+
if(env->timer_triggers_size > 0) {
209+
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
210+
LF_ASSERT(env->timer_triggers, "Out of memory");
211+
} else {
212+
env->timer_triggers = NULL;
213+
}
202214

203215
env->startup_reactions_size=num_startup_reactions;
204-
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
205-
LF_ASSERT(env->startup_reactions, "Out of memory");
216+
if (env->startup_reactions_size > 0) {
217+
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
218+
LF_ASSERT(env->startup_reactions, "Out of memory");
219+
} else {
220+
env->startup_reactions = NULL;
221+
}
206222

207223
env->shutdown_reactions_size=num_shutdown_reactions;
208-
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
209-
LF_ASSERT(env->shutdown_reactions, "Out of memory");
224+
if(env->shutdown_reactions_size > 0) {
225+
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
226+
LF_ASSERT(env->shutdown_reactions, "Out of memory");
227+
} else {
228+
env->shutdown_reactions = NULL;
229+
}
210230

211231
env->reset_reactions_size=num_reset_reactions;
212-
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
213-
LF_ASSERT(env->reset_reactions, "Out of memory");
232+
if (env->reset_reactions_size > 0) {
233+
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
234+
LF_ASSERT(env->reset_reactions, "Out of memory");
235+
} else {
236+
env->reset_reactions = NULL;
237+
}
214238

215239
env->is_present_fields_size = num_is_present_fields;
216240
env->is_present_fields_abbreviated_size = 0;
217241

218-
env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
219-
LF_ASSERT(env->is_present_fields, "Out of memory");
220-
221-
env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
222-
LF_ASSERT(env->is_present_fields_abbreviated, "Out of memory");
242+
if (env->is_present_fields_size > 0) {
243+
env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
244+
LF_ASSERT(env->is_present_fields, "Out of memory");
245+
env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
246+
LF_ASSERT(env->is_present_fields_abbreviated, "Out of memory");
247+
} else {
248+
env->is_present_fields = NULL;
249+
env->is_present_fields_abbreviated = NULL;
250+
}
223251

224252
env->_lf_handle=1;
225253

core/federated/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(FEDERATED_SOURCES clock-sync.c federate.c)
2-
list(APPEND INFO_SOURCES ${FEDERATED_SOURCES})
32

43
list(TRANSFORM FEDERATED_SOURCES PREPEND federated/)
5-
target_sources(core PRIVATE ${FEDERATED_SOURCES})
4+
list(APPEND REACTORC_SOURCES ${FEDERATED_SOURCES})
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LF_NETWORK_FILES net_util.c)
2-
list(APPEND INFO_SOURCES ${LF_NETWORK_FILES})
32

43
list(TRANSFORM LF_NETWORK_FILES PREPEND federated/network/)
5-
target_sources(core PRIVATE ${LF_NETWORK_FILES})
4+
list(APPEND REACTORC_SOURCES ${LF_NETWORK_FILES})

core/modal_models/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(MODAL_SOURCES modes.c)
2-
list(APPEND INFO_SOURCES ${MODAL_SOURCES})
32

43
list(TRANSFORM MODAL_SOURCES PREPEND modal_models/)
5-
target_sources(core PRIVATE ${MODAL_SOURCES})
4+
list(APPEND REACTORC_SOURCES ${MODAL_SOURCES})

core/platform/CMakeLists.txt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,32 @@
22
# file and assign the file's path to LF_PLATFORM_FILE
33

44
set(LF_PLATFORM_FILES
5-
lf_unix_clock_support.c
6-
lf_unix_syscall_support.c
7-
lf_linux_support.c
8-
lf_macos_support.c
9-
lf_windows_support.c
10-
lf_nrf52_support.c
11-
lf_zephyr_support.c
12-
lf_zephyr_clock_counter.c
13-
lf_zephyr_clock_kernel.c
14-
lf_rp2040_support.c
5+
lf_unix_clock_support.c
6+
lf_unix_syscall_support.c
7+
lf_linux_support.c
8+
lf_macos_support.c
9+
lf_windows_support.c
10+
lf_nrf52_support.c
11+
lf_zephyr_support.c
12+
lf_zephyr_clock_counter.c
13+
lf_zephyr_clock_kernel.c
14+
lf_rp2040_support.c
1515
)
1616

1717
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
1818
set(CMAKE_SYSTEM_VERSION 10.0)
1919
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
2020
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Nrf52")
21-
target_compile_definitions(core PUBLIC PLATFORM_NRF52)
21+
list(APPEND REACTORC_COMPILE_DEFS PLATFORM_NRF52)
2222
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
23-
target_compile_definitions(core PUBLIC PLATFORM_ZEPHYR)
23+
list(APPEND REACTORC_COMPILE_DEFS PLATFORM_ZEPHYR)
24+
set(PLATFORM_ZEPHYR true)
2425
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040")
25-
target_compile_definitions(core PUBLIC PLATFORM_RP2040)
26+
list(APPEND REACTORC_COMPILE_DEFS PLATFORM_RP2040)
2627
endif()
2728

28-
# Add sources to the list for debug info
29-
list(APPEND INFO_SOURCES ${LF_PLATFORM_FILES})
30-
3129
# Prepend all sources with platform
3230
list(TRANSFORM LF_PLATFORM_FILES PREPEND platform/)
3331

34-
# Add sources to core lib
35-
target_sources(core PRIVATE ${LF_PLATFORM_FILES})
32+
# Add sources to the list for debug info
33+
list(APPEND REACTORC_SOURCES ${LF_PLATFORM_FILES})

core/threaded/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ set(
88
scheduler_instance.c
99
watchdog.c
1010
)
11-
list(APPEND INFO_SOURCES ${THREADED_SOURCES})
1211

1312
list(TRANSFORM THREADED_SOURCES PREPEND threaded/)
14-
target_sources(core PRIVATE ${THREADED_SOURCES})
13+
list(APPEND REACTORC_SOURCES ${THREADED_SOURCES})
1514

core/utils/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
set(UTIL_SOURCES vector.c pqueue_base.c pqueue_tag.c pqueue.c util.c lf_semaphore.c)
22

3-
list(APPEND INFO_SOURCES ${UTIL_SOURCES})
43

54
list(TRANSFORM UTIL_SOURCES PREPEND utils/)
6-
target_sources(core PRIVATE ${UTIL_SOURCES})
5+
list(APPEND REACTORC_SOURCES ${UTIL_SOURCES})
76

87
# Include sources from subdirectories
98
include(utils/hashset/CMakeLists.txt)

core/utils/hashset/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
set(HASHSET_SOURCES hashset.c hashset_itr.c)
22

3-
list(APPEND INFO_SOURCES ${HASHSET_SOURCES})
43

54
list(TRANSFORM HASHSET_SOURCES PREPEND utils/hashset/)
6-
target_sources(core PRIVATE ${HASHSET_SOURCES})
5+
list(APPEND REACTORC_SOURCES ${HASHSET_SOURCES})

0 commit comments

Comments
 (0)