X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/0f809e5fbebb36788aea3523be7f93c04f2c7f8c..acb0ef5801fc0caafdcfd34ae62e48d276866a1b:/qemu-timer.c diff --git a/qemu-timer.c b/qemu-timer.c index 0305ad5313..00a5d35c3f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -56,7 +56,7 @@ typedef struct QEMUClock { } QEMUClock; QEMUTimerListGroup main_loop_tlg; -QEMUClock qemu_clocks[QEMU_CLOCK_MAX]; +static QEMUClock qemu_clocks[QEMU_CLOCK_MAX]; /* A QEMUTimerList is a list of timers attached to a clock. More * than one QEMUTimerList can be attached to each clock, for instance @@ -126,6 +126,9 @@ static void qemu_clock_init(QEMUClockType type) { QEMUClock *clock = qemu_clock_ptr(type); + /* Assert that the clock of type TYPE has not been initialized yet. */ + assert(main_loop_tlg.tl[type] == NULL); + clock->type = type; clock->enabled = true; clock->last = INT64_MIN; @@ -410,11 +413,40 @@ void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) } } +/* modify the current timer so that it will be fired when current_time + >= expire_time or the current deadline, whichever comes earlier. + The corresponding callback will be called. */ +void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t expire_time) +{ + QEMUTimerList *timer_list = ts->timer_list; + bool rearm; + + qemu_mutex_lock(&timer_list->active_timers_lock); + if (ts->expire_time == -1 || ts->expire_time > expire_time) { + if (ts->expire_time != -1) { + timer_del_locked(timer_list, ts); + } + rearm = timer_mod_ns_locked(timer_list, ts, expire_time); + } else { + rearm = false; + } + qemu_mutex_unlock(&timer_list->active_timers_lock); + + if (rearm) { + timerlist_rearm(timer_list); + } +} + void timer_mod(QEMUTimer *ts, int64_t expire_time) { timer_mod_ns(ts, expire_time * ts->scale); } +void timer_mod_anticipate(QEMUTimer *ts, int64_t expire_time) +{ + timer_mod_anticipate_ns(ts, expire_time * ts->scale); +} + bool timer_pending(QEMUTimer *ts) { return ts->expire_time >= 0;