Skip to content

Commit

Permalink
Fix potential concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
knokko committed Feb 13, 2024
1 parent 865d7f2 commit f2159d1
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ public void stop() {
}

private long determineSleepTime(long currentTime) {
long nextUpdateAt = reference.time + reference.counter * period;
Reference currentReference = reference;
long nextUpdateAt = currentReference.time + currentReference.counter * period;
long nextSleepTime = nextUpdateAt - currentTime;

if (-nextSleepTime > maximumBacklog) reference.time += -nextSleepTime - maximumBacklog;
if (-nextSleepTime > maximumBacklog) currentReference.time += -nextSleepTime - maximumBacklog;

return nextSleepTime / 1000_000L;
}
Expand Down

0 comments on commit f2159d1

Please sign in to comment.