Skip to content

Commit

Permalink
Factor setting and waiting for start time into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Dec 9, 2024
1 parent 8c9ca08 commit 5929abc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
13 changes: 3 additions & 10 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) {

LF_PRINT_DEBUG("Initializing.");
initialize_global();
// Set start time
if (!start_time_specified) {
start_time = lf_time_physical();
} else {
instant_t now = lf_time_physical();
if (now < start_time) {
LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now);
lf_sleep(start_time - now);
}
}
// Set the start time of the program (if it is not set from the command line). Possibly wait for
// it to arrive also.
_lf_set_and_wait_for_start_time();
#ifndef FEDERATED
lf_tracing_set_start_time(start_time);
#endif
Expand Down
12 changes: 12 additions & 0 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,3 +1261,15 @@ index_t lf_combine_deadline_and_level(interval_t deadline, int level) {
else
return (deadline << 16) | level;
}

void _lf_set_and_wait_for_start_time() {
if (!start_time_specified) {
start_time = lf_time_physical();
} else {
instant_t now = lf_time_physical();
if (!fast && now < start_time) {
lf_print("Sleeping " PRINTF_TIME " ns until specified start time", start_time - now);
lf_sleep(start_time - now);
}
}
}
12 changes: 3 additions & 9 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,9 @@ int lf_reactor_c_main(int argc, const char* argv[]) {

// Initialize the clock through the platform API. No reading of physical time before this.
_lf_initialize_clock();
if (!start_time_specified) {
start_time = lf_time_physical();
} else {
instant_t now = lf_time_physical();
if (now < start_time) {
LF_PRINT_LOG("Sleeping " PRINTF_TIME " ns until start time", start_time - now);
lf_sleep(start_time - now);
}
}
// Set the start time of the program (if it is not set from the command line). Possibly wait for
// it to arrive also.
_lf_set_and_wait_for_start_time();
#ifndef FEDERATED
lf_tracing_set_start_time(start_time);
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/core/reactor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ extern struct allocation_record_t* _lf_reactors_to_free;

////////////////////// Functions //////////////////////


/**
* @brief Set the start time of the program and possibly wait for it to arrive.
*/
void _lf_set_and_wait_for_start_time();

/**
* @brief Combine a deadline and a level into a single index for sorting in the reaction queue.
*
Expand Down

0 comments on commit 5929abc

Please sign in to comment.