From 3a9c7b152c283ab27e97cde36437fbdb4152994b Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 14 Aug 2023 22:26:41 +0200 Subject: [PATCH] Fixes for the advanced timer API. --- src/include/86box/timer.h | 10 +++++++++- src/timer.c | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/include/86box/timer.h b/src/include/86box/timer.h index e38ac51a3..8e4adf80d 100644 --- a/src/include/86box/timer.h +++ b/src/include/86box/timer.h @@ -117,6 +117,13 @@ timer_is_enabled(pc_timer_t *timer) return !!(timer->flags & TIMER_ENABLED); } +/*True if timer currently enabled*/ +static __inline int +timer_is_on(pc_timer_t *timer) +{ + return ((timer->flags & TIMER_ENABLED) && (timer->period > 0.0)); +} + /*Return integer timestamp of timer*/ static __inline uint32_t timer_get_ts_int(pc_timer_t *timer) @@ -204,12 +211,13 @@ timer_process_inline(void) timer_head->prev = NULL; timer->next = timer->prev = NULL; - timer->flags &= ~TIMER_ENABLED; if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ timer->callback(timer->priv); + + timer->flags &= ~TIMER_ENABLED; } timer_target = timer_head->ts.ts32.integer; diff --git a/src/timer.c b/src/timer.c index e863c2f21..314e8a698 100644 --- a/src/timer.c +++ b/src/timer.c @@ -118,12 +118,13 @@ timer_process(void) timer_head->prev = NULL; timer->next = timer->prev = NULL; - timer->flags &= ~TIMER_ENABLED; if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ timer->callback(timer->priv); + + timer->flags &= ~TIMER_ENABLED; } timer_target = timer_head->ts.ts32.integer; @@ -232,7 +233,7 @@ timer_on_auto(pc_timer_t *timer, double period) return; if (period > 0.0) - timer_on(timer, period, (timer->period == 0.0)); + timer_on(timer, period, !(timer->flags & TIMER_ENABLED) && (timer->period == 0.0)); else timer_stop(timer); }