Received: from eggs.gnu.org ([2001:4830:134:3::10]:41381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWppK-00072R-Hp for qemu-devel@nongnu.org; Thu, 17 Oct 2013 11:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWppD-0000n7-Ot for qemu-devel@nongnu.org; Thu, 17 Oct 2013 11:49:30 -0400 Received: from mail-ee0-x22c.google.com ([2a00:1450:4013:c00::22c]:51164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWppD-0000mw-I9 for qemu-devel@nongnu.org; Thu, 17 Oct 2013 11:49:23 -0400 Received: by mail-ee0-f44.google.com with SMTP id b47so1187661eek.31 for ; Thu, 17 Oct 2013 08:49:22 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 17 Oct 2013 17:48:48 +0200 Message-Id: <1382024935-28297-11-git-send-email-pbonzini@redhat.com> In-Reply-To: <1382024935-28297-1-git-send-email-pbonzini@redhat.com> References: <1382024935-28297-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 10/17] timer: extract timer_mod_ns_locked and timerlist_rearm List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org These will be reused in timer_mod_anticipate functions. Reviewed-by: Alex Bligh Signed-off-by: Paolo Bonzini --- qemu-timer.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index 2b533da..0305ad5 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); } } -- 1.8.3.1