Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont apply/subtract clock sync offset from NEVER/FOREVER #427

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/federated/clock-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,13 @@ void* listen_to_rti_UDP_thread(void* args) {
// If clock synchronization is enabled, provide implementations. If not
// just empty implementations that should be optimized away.
#if (LF_CLOCK_SYNC >= LF_CLOCK_SYNC_INIT)
void clock_sync_add_offset(instant_t* t) { *t += (_lf_clock_sync_offset + _lf_clock_sync_constant_bias); }
void clock_sync_add_offset(instant_t* t) {
*t = lf_time_add(*t, (_lf_clock_sync_offset + _lf_clock_sync_constant_bias));
}

void clock_sync_subtract_offset(instant_t* t) { *t -= (_lf_clock_sync_offset + _lf_clock_sync_constant_bias); }
void clock_sync_subtract_offset(instant_t* t) {
*t = lf_time_add(*t, -(_lf_clock_sync_offset + _lf_clock_sync_constant_bias));
}

void clock_sync_set_constant_bias(interval_t offset) { _lf_clock_sync_constant_bias = offset; }
#else // i.e. (LF_CLOCK_SYNC < LF_CLOCK_SYNC_INIT)
Expand Down
43 changes: 33 additions & 10 deletions core/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,43 @@ tag_t lf_tag(void* env) {
return ((environment_t*)env)->current_tag;
}

instant_t lf_time_add(instant_t a, interval_t b) {
if (a == NEVER || b == NEVER) {
return NEVER;
}
if (a == FOREVER || b == FOREVER) {
return FOREVER;
}
instant_t res = a + b;
// Check for overflow
if (res < a && b > 0) {
return FOREVER;
}
// Check for underflow
if (res > a && b < 0) {
return NEVER;
}
return res;
}

tag_t lf_tag_add(tag_t a, tag_t b) {
if (a.time == NEVER || b.time == NEVER)
return NEVER_TAG;
if (a.time == FOREVER || b.time == FOREVER)
instant_t res = lf_time_add(a.time, b.time);
if (res == FOREVER) {
return FOREVER_TAG;
if (b.time > 0)
}
if (res == NEVER) {
return NEVER_TAG;
}

if (b.time > 0) {
a.microstep = 0; // Ignore microstep of first arg if time of second is > 0.
tag_t result = {.time = a.time + b.time, .microstep = a.microstep + b.microstep};
if (result.microstep < a.microstep)
return FOREVER_TAG;
if (result.time < a.time && b.time > 0)
}
tag_t result = {.time = res, .microstep = a.microstep + b.microstep};

// If microsteps overflows
if (result.microstep < a.microstep) {
return FOREVER_TAG;
if (result.time > a.time && b.time < 0)
return NEVER_TAG;
}
return result;
}

Expand Down
9 changes: 9 additions & 0 deletions tag/api/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ tag_t lf_tag(void* env);
*/
tag_t lf_tag_add(tag_t a, tag_t b);

/**
* Adds an interval to an instant, checks for overflows and underflows.
*
* @param a
* @param b
* @return instant_t
*/
instant_t lf_time_add(instant_t a, interval_t b);

/**
* Compare two tags. Return -1 if the first is less than
* the second, 0 if they are equal, and +1 if the first is
Expand Down
Loading