Patchwork [1/8] timers: extract timer_mod_ns_locked and timerlist_rearm

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 8, 2013, 8:47 a.m.
Message ID <1381222058-16701-2-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/281361/
State New
Headers show

Comments

Paolo Bonzini - Oct. 8, 2013, 8:47 a.m.
These will be reused in timer_mod_anticipate functions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c | 51 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 19 deletions(-)
Alex Bligh - Oct. 8, 2013, 9:06 a.m.
On 8 Oct 2013, at 09:47, Paolo Bonzini wrote:

> These will be reused in timer_mod_anticipate functions.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
> ---
> qemu-timer.c | 51 ++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 32 insertions(+), 19 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 6b62e88..95fc6eb 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -338,6 +338,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)
> {
> @@ -353,30 +381,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
> 
> 
> 
>

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 6b62e88..95fc6eb 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -338,6 +338,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)
 {
@@ -353,30 +381,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);
     }
 }