qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC v4 15/27] monitor: let monitor_{suspend|resume} thread


From: Peter Xu
Subject: [Qemu-devel] [RFC v4 15/27] monitor: let monitor_{suspend|resume} thread safe
Date: Thu, 16 Nov 2017 21:05:58 +0800

Monitor code now can be run in more than one thread.  Let the suspend
and resume code be thread safe.

Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
---
 monitor.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/monitor.c b/monitor.c
index ec03f1b232..30f9cd80de 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4003,7 +4003,7 @@ int monitor_suspend(Monitor *mon)
 {
     if (!mon->rs)
         return -ENOTTY;
-    mon->suspend_cnt++;
+    atomic_inc(&mon->suspend_cnt);
     return 0;
 }
 
@@ -4011,8 +4011,9 @@ void monitor_resume(Monitor *mon)
 {
     if (!mon->rs)
         return;
-    if (--mon->suspend_cnt == 0)
+    if (atomic_dec_fetch(&mon->suspend_cnt) == 0) {
         readline_show_prompt(mon->rs);
+    }
 }
 
 static QObject *get_qmp_greeting(void)
-- 
2.13.6




reply via email to

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