[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v6 14/27] monitor: let suspend_cnt be thread safe
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [RFC v6 14/27] monitor: let suspend_cnt be thread safe |
Date: |
Fri, 12 Jan 2018 15:48:10 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
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 <address@hidden>
> ---
> 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 <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [RFC v6 14/27] monitor: let suspend_cnt be thread safe,
Eric Blake <=