qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/9] main-loop: introduce a main_loop_quit() functio


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 1/9] main-loop: introduce a main_loop_quit() function
Date: Wed, 20 Feb 2013 09:32:41 -0600

Today the only way the main loop exits is upon a system shutdown
request.  This is baked into the logic of the main loop.

Introduce a main_loop_quit function to explicitly request that
the main loop exits and refactor shutdown to use it.  This is
closer to how most main loops work.

Signed-off-by: Anthony Liguori <address@hidden>
---
 include/qemu/main-loop.h |  3 +++
 main-loop.c              | 13 +++++++++++++
 vl.c                     |  9 +++++----
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index e8059c3..758b435 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -303,4 +303,7 @@ void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, 
fd_set *xfds, int rc
 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
 void qemu_bh_schedule_idle(QEMUBH *bh);
 
+bool main_loop_should_quit(void);
+void main_loop_quit(void);
+
 #endif
diff --git a/main-loop.c b/main-loop.c
index 6f52ac3..d433c45 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -392,6 +392,19 @@ static int os_host_main_loop_wait(uint32_t timeout)
 }
 #endif
 
+static bool do_main_loop_quit;
+
+bool main_loop_should_quit(void)
+{
+    return do_main_loop_quit;
+}
+
+void main_loop_quit(void)
+{
+    do_main_loop_quit = true;
+    qemu_notify_event();
+}
+
 int main_loop_wait(int nonblocking)
 {
     int ret;
diff --git a/vl.c b/vl.c
index c5b0eea..d6c5626 100644
--- a/vl.c
+++ b/vl.c
@@ -1942,7 +1942,7 @@ void qemu_system_vmstop_request(RunState state)
     qemu_notify_event();
 }
 
-static bool main_loop_should_exit(void)
+static void main_loop_junk(void)
 {
     RunState r;
     if (qemu_debug_requested()) {
@@ -1957,7 +1957,8 @@ static bool main_loop_should_exit(void)
         if (no_shutdown) {
             vm_stop(RUN_STATE_SHUTDOWN);
         } else {
-            return true;
+            main_loop_quit();
+            return;
         }
     }
     if (qemu_reset_requested()) {
@@ -1983,7 +1984,6 @@ static bool main_loop_should_exit(void)
     if (qemu_vmstop_requested(&r)) {
         vm_stop(r);
     }
-    return false;
 }
 
 static void main_loop(void)
@@ -2002,7 +2002,8 @@ static void main_loop(void)
 #ifdef CONFIG_PROFILER
         dev_time += profile_getclock() - ti;
 #endif
-    } while (!main_loop_should_exit());
+        main_loop_junk();
+    } while (!main_loop_should_quit());
 }
 
 static void version(void)
-- 
1.8.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]