qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <weil@mail.berlios.de>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 1/4] qemu-timer: Add and use new function qemu_timer_expired_ns
Date: Sun, 10 Apr 2011 20:28:40 +0200	[thread overview]
Message-ID: <1302460123-25704-2-git-send-email-weil@mail.berlios.de> (raw)
In-Reply-To: <1302460123-25704-1-git-send-email-weil@mail.berlios.de>

This simply moves code which is used three times
into a new function thus improving readability.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 qemu-timer.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 50f1943..c3ad72a 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -177,6 +177,11 @@ struct qemu_alarm_timer {
 
 static struct qemu_alarm_timer *alarm_timer;
 
+static bool qemu_timer_expired_ns(QEMUTimer *timer_head, int64_t current_time)
+{
+    return timer_head && (timer_head->expire_time <= current_time);
+}
+
 int qemu_alarm_pending(void)
 {
     return alarm_timer->pending;
@@ -438,10 +443,9 @@ static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
     pt = &active_timers[ts->clock->type];
     for(;;) {
         t = *pt;
-        if (!t)
-            break;
-        if (t->expire_time > expire_time)
+        if (!qemu_timer_expired_ns(t, expire_time)) {
             break;
+        }
         pt = &t->next;
     }
     ts->expire_time = expire_time;
@@ -478,9 +482,7 @@ int qemu_timer_pending(QEMUTimer *ts)
 
 int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
 {
-    if (!timer_head)
-        return 0;
-    return (timer_head->expire_time <= current_time * timer_head->scale);
+    return qemu_timer_expired_ns(timer_head, current_time * timer_head->scale);
 }
 
 static void qemu_run_timers(QEMUClock *clock)
@@ -495,8 +497,9 @@ static void qemu_run_timers(QEMUClock *clock)
     ptimer_head = &active_timers[clock->type];
     for(;;) {
         ts = *ptimer_head;
-        if (!ts || ts->expire_time > current_time)
+        if (!qemu_timer_expired_ns(ts, current_time)) {
             break;
+        }
         /* remove timer from the list before calling the callback */
         *ptimer_head = ts->next;
         ts->next = NULL;
-- 
1.7.2.5

  reply	other threads:[~2011-04-10 18:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-10 18:28 [Qemu-devel] qemu-timer: Clean code and re-add multimedia timers for windows Stefan Weil
2011-04-10 18:28 ` Stefan Weil [this message]
2011-04-20 14:26   ` [Qemu-devel] [PULL] qemu-timer: Add and use new function qemu_timer_expired_ns and other patches Stefan Weil
2011-04-28 12:18     ` Stefan Weil
2011-04-29 21:09       ` Blue Swirl
2011-04-10 18:28 ` [Qemu-devel] [PATCH 2/4] qemu-timer: Remove unneeded include statement (w32) Stefan Weil
2011-04-10 18:28 ` [Qemu-devel] [PATCH 3/4] qemu-timer: Avoid type casts Stefan Weil
2011-04-10 18:28 ` [Qemu-devel] [PATCH 4/4] qemu-timer: Fix timers for w32 Stefan Weil
2011-04-11  7:36   ` [Qemu-devel] " Paolo Bonzini
2011-04-11 17:21     ` [Qemu-devel] " Stefan Weil
2011-04-12 12:36       ` Jan Kiszka
2011-04-12 12:40         ` Paolo Bonzini
2011-04-12 12:59           ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302460123-25704-2-git-send-email-weil@mail.berlios.de \
    --to=weil@mail.berlios.de \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).