summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2021-01-28 11:06:58 +0000
committerratchov <ratchov@openbsd.org>2021-01-28 11:06:58 +0000
commit540a9b644530a7facb9f69c2d6e730ae4b776abe (patch)
tree330dcdca3e87dd733baa0ba7a6ff94776e413df6
parentMake slot_{attach,detach}() the opposite of each other (diff)
downloadwireguard-openbsd-540a9b644530a7facb9f69c2d6e730ae4b776abe.tar.xz
wireguard-openbsd-540a9b644530a7facb9f69c2d6e730ae4b776abe.zip
Use everywhere the same pattern to handle fractional clock ticks
No behavior change; this change is only to make the maths easier to proofread
-rw-r--r--usr.bin/sndiod/dev.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 2f425dac7d7..e416f33f0f8 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -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);
}