Skip to content

Commit bb552dc

Browse files
committed
Rename MIN_SLEEP_DURATION to lf_min_sleep_duration and update comments
1 parent 61d6ef2 commit bb552dc

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

core/federated/federate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,13 @@ static void* update_ports_from_staa_offsets(void* args) {
11231123
// we require a minimum wait time here. Note that zero-valued STAAs are
11241124
// included, and STA might be zero or very small.
11251125
// In this case, this thread will fail to ever release the environment mutex.
1126-
// This causes chaos. The MIN_SLEEP_DURATION is the smallest amount of time
1126+
// This causes chaos. The lf_min_sleep_duration is the smallest amount of time
11271127
// that wait_until will actually wait. Note that this strategy does not
11281128
// block progress of any execution that is actually processing events.
11291129
// It only slightly delays the decision that an event is absent, and only
11301130
// if the STAA and STA are extremely small.
1131-
if (wait_time < 5 * MIN_SLEEP_DURATION) {
1132-
wait_until_time += 5 * MIN_SLEEP_DURATION;
1131+
if (wait_time < 5 * lf_min_sleep_duration) {
1132+
wait_until_time += 5 * lf_min_sleep_duration;
11331133
}
11341134
while (a_port_is_unknown(staa_elem)) {
11351135
LF_PRINT_DEBUG("**** (update thread) waiting until: " PRINTF_TIME, wait_until_time - lf_time_start());
@@ -1197,7 +1197,7 @@ static void* update_ports_from_staa_offsets(void* args) {
11971197
// The wait is necessary to prevent a busy wait, which will only occur if port
11981198
// status are always known inside the while loop
11991199
// Be sure to use wait_until() instead of sleep() because sleep() will not release the mutex.
1200-
instant_t wait_until_time = lf_time_add(env->current_tag.time, 2 * MIN_SLEEP_DURATION);
1200+
instant_t wait_until_time = lf_time_add(env->current_tag.time, 2 * lf_min_sleep_duration);
12011201
wait_until(wait_until_time, &lf_port_status_changed);
12021202

12031203
continue;

core/threaded/reactor_threaded.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ bool wait_until(instant_t wait_until_time, lf_cond_t* condition) {
201201
LF_PRINT_DEBUG("-------- Waiting until physical time " PRINTF_TIME, wait_until_time - start_time);
202202
// Check whether we actually need to wait, or if we have already passed the timepoint.
203203
interval_t wait_duration = wait_until_time - lf_time_physical();
204-
if (wait_duration < MIN_SLEEP_DURATION) {
205-
LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than MIN_SLEEP_DURATION " PRINTF_TIME ". Skipping wait.",
206-
wait_duration, MIN_SLEEP_DURATION);
204+
if (wait_duration < lf_min_sleep_duration) {
205+
LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than lf_min_sleep_duration " PRINTF_TIME ". Performing busy wait.",
206+
wait_duration, lf_min_sleep_duration);
207207
while (lf_time_physical() < wait_until_time) {
208208
//Busy wait
209209
}

include/core/reactor_common.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@
2929
#include "modes.h"
3030
#include "port.h"
3131

32-
////////////////////// Constants & Macros //////////////////////
33-
34-
/**
35-
* @brief Constant giving the minimum amount of time to sleep to wait
36-
* for physical time to reach a logical time.
37-
*
38-
* Unless the "fast" option is given, an LF program will wait until
39-
* physical time matches logical time before handling an event with
40-
* a given logical time. The amount of time is less than this given
41-
* threshold, then no wait will occur. The purpose of this is
42-
* to prevent unnecessary delays caused by simply setting up and
43-
* performing the wait.
44-
*/
45-
// #define MIN_SLEEP_DURATION USEC(10)
46-
4732
////////////////////// Global Variables //////////////////////
4833

4934
// The following variables are defined in reactor_common.c and used in reactor.c,

include/core/threaded/reactor_threaded.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ void lf_synchronize_with_other_federates(void);
9494
*
9595
* The mutex lock associated with the condition argument is assumed to be held by
9696
* the calling thread. This mutex is released while waiting. If the wait time is
97-
* too small to actually wait (less than MIN_SLEEP_DURATION), then this function
98-
* immediately returns true and the mutex is not released.
97+
* too small (less than lf_min_sleep_duration) to wait using lf_clock_cond_timedwait,
98+
* then this function performs busy wait and the mutex is not released.
9999
*
100100
* @param env Environment within which we are executing.
101101
* @param wait_until_time The time to wait until physical time matches it.

low_level_platform/api/platform/lf_unix_clock_support.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#include <time.h>
22
#include <errno.h>
33

4-
extern instant_t MIN_SLEEP_DURATION;
4+
/**
5+
* @brief Constant giving the minimum amount of time to sleep to wait
6+
* for physical time to reach a logical time.
7+
*
8+
* Unless the "fast" option is given, an LF program will wait until
9+
* physical time matches logical time before handling an event with
10+
* a given logical time. The amount of time is less than this given
11+
* threshold, then no wait will occur. The purpose of this is
12+
* to prevent unnecessary delays caused by simply setting up and
13+
* performing the wait.
14+
*/
15+
extern instant_t lf_min_sleep_duration;
516

617
/**
718
* @brief Convert a _lf_time_spec_t ('tp') to an instant_t representation in

low_level_platform/impl/src/lf_unix_clock_support.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "logging.h"
77
#include "platform/lf_unix_clock_support.h"
88

9-
instant_t MIN_SLEEP_DURATION;
9+
instant_t lf_min_sleep_duration;
1010

1111
instant_t convert_timespec_to_ns(struct timespec tp) { return ((instant_t)tp.tv_sec) * BILLION + tp.tv_nsec; }
1212

@@ -25,7 +25,7 @@ void _lf_initialize_clock() {
2525
}
2626

2727
lf_print("---- System clock resolution: %ld nsec", res.tv_nsec);
28-
MIN_SLEEP_DURATION = NSEC(res.tv_nsec);
28+
lf_min_sleep_duration = NSEC(res.tv_nsec);
2929
}
3030

3131
/**

0 commit comments

Comments
 (0)