[Qemu-devel] [RFC v3 16/27] monitor: let monitor_{suspend|resume} thread safe

Peter Xu posted 27 patches 8 years, 3 months ago
There is a newer version of this series
[Qemu-devel] [RFC v3 16/27] monitor: let monitor_{suspend|resume} thread safe
Posted by Peter Xu 8 years, 3 months ago
Monitor code now can be run in more than one thread.  Let the suspend
and resume code for thread safety.
---
 monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/monitor.c b/monitor.c
index 1e87de87f8..47e969244d 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,7 +4011,7 @@ 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);
 }
 
-- 
2.13.5


Re: [Qemu-devel] [RFC v3 16/27] monitor: let monitor_{suspend|resume} thread safe
Posted by Fam Zheng 8 years, 3 months ago
On Mon, 11/06 17:46, Peter Xu wrote:
> Monitor code now can be run in more than one thread.  Let the suspend
> and resume code for thread safety.

s/for thread safety/be thread safe/

Apart from that,

Reviewed-by: Fam Zheng <famz@redhat.com>