diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-06-16 17:40:18 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-06-16 17:40:18 -0700 |
commit | 256d7c17e9269f82a8f006dc50308d7934b93ce3 (patch) | |
tree | e468967895857a03e74b0ff5c35b7d8d2cee19d1 | |
parent | 30276a47a0c454691c586bdc88dea87c2e82c19a (diff) | |
download | pw-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.
-rw-r--r-- | pw.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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; |