aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-06-16 17:40:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-06-16 17:40:18 -0700
commit256d7c17e9269f82a8f006dc50308d7934b93ce3 (patch)
treee468967895857a03e74b0ff5c35b7d8d2cee19d1 /pw.c
parent30276a47a0c454691c586bdc88dea87c2e82c19a (diff)
downloadpw-256d7c17e9269f82a8f006dc50308d7934b93ce3.tar.gz
pw-256d7c17e9269f82a8f006dc50308d7934b93ce3.tar.bz2
pw-256d7c17e9269f82a8f006dc50308d7934b93ce3.zip
bugfix: hokey long interval calculation.
The intent is to have a clock which measures milliseconds and wraps around from 1000000000 (billion) back to zero, fitting into 32 bits. The now - lastttime calculation must be done modulo a billion. The difference could be negative because of the wrap; to ensure we get a positive residue, we add a billion.
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/pw.c b/pw.c
index 7f98136..44d0faa 100644
--- a/pw.c
+++ b/pw.c
@@ -1571,7 +1571,9 @@ int main(int argc, char **argv)
gettimeofday(&tv, NULL);
now = tv.tv_sec % 1000000 * 1000 + tv.tv_usec / 1000;
- if (lasttime == -1 || now - lasttime > long_interval) {
+ if (lasttime == -1 ||
+ (now + 1000000000 - lasttime) % 1000000000 > long_interval)
+ {
if ((pw.stat & stat_dirty) && pw.nlines == pw.maxlines)
force = 1;
lasttime = now;