Skip to content

Commit 1e0267b

Browse files
authored
Merge pull request #514 from lf-lang/fix-wait-until
Perform busy waiting when the wait duration is less than `MIN_SLEEP_DURATION`
2 parents 856e98a + 98b1090 commit 1e0267b

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

core/threaded/reactor_threaded.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ bool wait_until(instant_t wait_until_time, lf_cond_t* condition) {
199199
LF_PRINT_DEBUG("-------- Waiting until physical time " PRINTF_TIME, wait_until_time - start_time);
200200
// Check whether we actually need to wait, or if we have already passed the timepoint.
201201
interval_t wait_duration = wait_until_time - lf_time_physical();
202-
if (wait_duration < MIN_SLEEP_DURATION) {
203-
LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than MIN_SLEEP_DURATION " PRINTF_TIME ". Skipping wait.",
204-
wait_duration, MIN_SLEEP_DURATION);
202+
if (wait_duration < 0) {
203+
LF_PRINT_DEBUG("We have already passed " PRINTF_TIME ". Skipping wait.", wait_until_time);
205204
return true;
206205
}
207206

include/core/threaded/reactor_threaded.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ void lf_synchronize_with_other_federates(void);
9393
* if that event time matches or exceeds the specified time.
9494
*
9595
* The mutex lock associated with the condition argument is assumed to be held by
96-
* 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
96+
* the calling thread. This mutex is released while waiting. If the current physical
97+
* time has already passed the specified time, then this function
9898
* immediately returns true and the mutex is not released.
9999
*
100100
* @param env Environment within which we are executing.

0 commit comments

Comments
 (0)