Skip to content

Commit

Permalink
Merge pull request #417 from lf-lang/watchdog-fix
Browse files Browse the repository at this point in the history
Fix race condition in lf_watchdog_stop
  • Loading branch information
erlingrj authored May 2, 2024
2 parents 329528f + 38ed044 commit f64c02d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/threaded/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ void lf_watchdog_start(watchdog_t* watchdog, interval_t additional_timeout) {
}

void lf_watchdog_stop(watchdog_t* watchdog) {
// If the watchdog isnt active, then it is no reason to stop it.
// Assumes reactor mutex is already held.
watchdog->expiration = NEVER;

// If lf_watchdog_stop is called very close to lf_watchdog_start, it might
// not have had the time to wake up and start sleeping.
if (!watchdog->active) {
return;
}

// Assumes reactor mutex is already held.
watchdog->expiration = NEVER;
LF_COND_SIGNAL(&watchdog->cond);
}

Expand Down

0 comments on commit f64c02d

Please sign in to comment.