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