Use everywhere the same pattern to handle fractional clock ticks
authorratchov <ratchov@openbsd.org>
Thu, 28 Jan 2021 11:06:58 +0000 (11:06 +0000)
committerratchov <ratchov@openbsd.org>
Thu, 28 Jan 2021 11:06:58 +0000 (11:06 +0000)
No behavior change; this change is only to make the maths easier to
proofread

usr.bin/sndiod/dev.c

index 2f425da..e416f33 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dev.c,v 1.79 2021/01/28 11:06:07 ratchov Exp $        */
+/*     $OpenBSD: dev.c,v 1.80 2021/01/28 11:06:58 ratchov Exp $        */
 /*
  * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
  *
@@ -948,9 +948,15 @@ dev_onmove(struct dev *d, int delta)
                 * s->ops->onmove() may remove the slot
                 */
                snext = s->next;
-               pos = (long long)delta * s->round + s->delta_rem;
+               pos = s->delta_rem +
+                   (long long)s->delta * d->round +
+                   (long long)delta * s->round;
+               s->delta = pos / (int)d->round;
                s->delta_rem = pos % d->round;
-               s->delta += pos / (int)d->round;
+               if (s->delta_rem < 0) {
+                       s->delta_rem += d->round;
+                       s->delta--;
+               }
                if (s->delta >= 0)
                        s->ops->onmove(s->arg);
        }