summaryrefslogtreecommitdiff
path: root/qemu-timer.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-10-03 15:06:39 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2013-10-17 17:30:59 +0200
commit0f809e5fbebb36788aea3523be7f93c04f2c7f8c (patch)
treeff85e6440cd7c90e1bac50ebd1d0fee6c23b6b87 /qemu-timer.c
parent3c05341157f4d08dc3cc8ffa675a0aaa4818d028 (diff)
downloadqemu-0f809e5fbebb36788aea3523be7f93c04f2c7f8c.tar.gz
qemu-0f809e5fbebb36788aea3523be7f93c04f2c7f8c.tar.bz2
qemu-0f809e5fbebb36788aea3523be7f93c04f2c7f8c.zip
timer: extract timer_mod_ns_locked and timerlist_rearm
These will be reused in timer_mod_anticipate functions. Reviewed-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-timer.c')
-rw-r--r--qemu-timer.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/qemu-timer.c b/qemu-timer.c
index 2b533da2c7..0305ad5313 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -355,6 +355,34 @@ static void timer_del_locked(QEMUTimerList *timer_list, QEMUTimer *ts)
}
}
+static bool timer_mod_ns_locked(QEMUTimerList *timer_list,
+ QEMUTimer *ts, int64_t expire_time)
+{
+ QEMUTimer **pt, *t;
+
+ /* add the timer in the sorted list */
+ pt = &timer_list->active_timers;
+ for (;;) {
+ t = *pt;
+ if (!timer_expired_ns(t, expire_time)) {
+ break;
+ }
+ pt = &t->next;
+ }
+ ts->expire_time = MAX(expire_time, 0);
+ ts->next = *pt;
+ *pt = ts;
+
+ return pt == &timer_list->active_timers;
+}
+
+static void timerlist_rearm(QEMUTimerList *timer_list)
+{
+ /* Interrupt execution to force deadline recalculation. */
+ qemu_clock_warp(timer_list->clock->type);
+ timerlist_notify(timer_list);
+}
+
/* stop a timer, but do not dealloc it */
void timer_del(QEMUTimer *ts)
{
@@ -370,30 +398,15 @@ void timer_del(QEMUTimer *ts)
void timer_mod_ns(QEMUTimer *ts, int64_t expire_time)
{
QEMUTimerList *timer_list = ts->timer_list;
- QEMUTimer **pt, *t;
+ bool rearm;
qemu_mutex_lock(&timer_list->active_timers_lock);
timer_del_locked(timer_list, ts);
-
- /* add the timer in the sorted list */
- pt = &timer_list->active_timers;
- for(;;) {
- t = *pt;
- if (!timer_expired_ns(t, expire_time)) {
- break;
- }
- pt = &t->next;
- }
- ts->expire_time = MAX(expire_time, 0);
- ts->next = *pt;
- *pt = ts;
+ rearm = timer_mod_ns_locked(timer_list, ts, expire_time);
qemu_mutex_unlock(&timer_list->active_timers_lock);
- /* Rearm if necessary */
- if (pt == &timer_list->active_timers) {
- /* Interrupt execution to force deadline recalculation. */
- qemu_clock_warp(timer_list->clock->type);
- timerlist_notify(timer_list);
+ if (rearm) {
+ timerlist_rearm(timer_list);
}
}