On 12/19/2017 02:45 AM, Peter Xu wrote: > Monitor code now can be run in more than one thread. Let it be thread > safe when accessing suspend_cnt counter. > > Signed-off-by: Peter Xu <pet...@redhat.com> > --- > monitor.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/monitor.c b/monitor.c > index cf1e5d881c..844508d134 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -3862,7 +3862,7 @@ static int monitor_can_read(void *opaque) > { > Monitor *mon = opaque; > > - return (mon->suspend_cnt == 0) ? 1 : 0; > + return (atomic_mb_read(&mon->suspend_cnt) == 0) ? 1 : 0;
Worth a comment at the declaration of suspend_cnt that it must be accessed atomically? I find anything that does '(boolexpr) ? 1 : 0' to be a pointless waste of typing. It is semantically equivalent and shorter to write either of: return atomic_mb_read(&mon->suspend_cnt) == 0; return !atomic_mb_read(&mon->suspend_cnt); At any rate, I checked that all uses of suspend_cnt were converted over to atomic API, so this looks correct, whether or not you add my tweaks. Reviewed-by: Eric Blake <ebl...@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature