From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF1No-0003q0-2L for qemu-devel@nongnu.org; Thu, 29 Aug 2013 08:31:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VF1Nf-0002CU-1R for qemu-devel@nongnu.org; Thu, 29 Aug 2013 08:31:28 -0400 Received: from mail-ee0-x234.google.com ([2a00:1450:4013:c00::234]:65466) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF1Ne-0002CI-RK for qemu-devel@nongnu.org; Thu, 29 Aug 2013 08:31:18 -0400 Received: by mail-ee0-f52.google.com with SMTP id c41so208937eek.11 for ; Thu, 29 Aug 2013 05:31:18 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 29 Aug 2013 14:30:59 +0200 Message-Id: <1377779462-24383-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1377779462-24383-1-git-send-email-pbonzini@redhat.com> References: <1377779462-24383-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 1/3] qemu-timer: do del+mod atomically List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemulist@gmail.com, stefanha@redhat.com Signed-off-by: Paolo Bonzini --- qemu-timer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index 04869f4..d650247 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -319,13 +319,10 @@ void timer_free(QEMUTimer *ts) g_free(ts); } -/* stop a timer, but do not dealloc it */ -void timer_del(QEMUTimer *ts) +static void timer_del_locked(QEMUTimerList *timer_list, QEMUTimer *ts) { - QEMUTimerList *timer_list = ts->timer_list; QEMUTimer **pt, *t; - qemu_mutex_lock(&timer_list->active_timers_lock); pt = &timer_list->active_timers; for(;;) { t = *pt; @@ -337,6 +334,15 @@ void timer_del(QEMUTimer *ts) } pt = &t->next; } +} + +/* stop a timer, but do not dealloc it */ +void timer_del(QEMUTimer *ts) +{ + QEMUTimerList *timer_list = ts->timer_list; + + qemu_mutex_lock(&timer_list->active_timers_lock); + timer_del_locked(timer_list, ts); qemu_mutex_unlock(&timer_list->active_timers_lock); } @@ -347,10 +353,10 @@ void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) QEMUTimerList *timer_list = ts->timer_list; QEMUTimer **pt, *t; - timer_del(ts); + qemu_mutex_lock(&timer_list->active_timers_lock); + timer_del_locked(timer_list, ts); /* add the timer in the sorted list */ - qemu_mutex_lock(&timer_list->active_timers_lock); pt = &timer_list->active_timers; for(;;) { t = *pt; -- 1.8.3.1