diff mbox series

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

Message ID 20171106094643.14881-17-peterx@redhat.com
State New
Headers show
Series [RFC,v3,01/27] char-io: fix possible race on IOWatchPoll | expand

Commit Message

Peter Xu Nov. 6, 2017, 9:46 a.m. UTC
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(-)

Comments

Fam Zheng Nov. 7, 2017, 7:26 a.m. UTC | #1
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>
diff mbox series

Patch

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);
 }