aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-10-03 16:13:05 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-10-03 16:13:05 -0700
commit6205d1e8f3294343e6a74cb882be781a53e6a269 (patch)
tree5260c3af54eeef1abd9baec2acd21eee051e4de6
parent3b1400407d962c26313966f9ef780a2bdcbc36e2 (diff)
downloadabc80sim-6205d1e8f3294343e6a74cb882be781a53e6a269.tar.gz
abc80sim-6205d1e8f3294343e6a74cb882be781a53e6a269.tar.xz
abc80sim-6205d1e8f3294343e6a74cb882be781a53e6a269.zip
clock: correct the computation of the next clock
-rw-r--r--clock.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/clock.c b/clock.c
index bf9e9a5..4afed65 100644
--- a/clock.c
+++ b/clock.c
@@ -107,26 +107,24 @@ void z80_poll_external(void)
{
uint64_t now = nstime();
uint64_t next = ~UINT64_C(0);
- struct abctimer *t = timers;
int i;
bool sleepy = limit_speed;
for (i = 0; i < ntimers; i++) {
+ struct abctimer *t = &timers[i];
if (t->period) {
uint64_t tnext = t->last + t->period;
if (unlikely(now >= tnext)) {
t->last += t->period;
- tnext += t->period;
if (unlikely(now >= tnext)) {
/* Missed tick(s), advance to skip missed */
t->last = now - (now - t->last) % t->period;
- tnext = t->last + t->period;
}
t->func();
sleepy = false; /* Just in case "now" is too far behind now */
+ } else if (next > tnext) {
+ next = tnext; /* The next event is closer than you thought */
}
- if (next > tnext)
- next = tnext;
}
}