[Spice-devel] [PATCH spice-server 01/11] stat-file: Protect flags field with atomic operation

Christophe Fergeau cfergeau at redhat.com
Tue Jan 16 12:35:00 UTC 2018


On Tue, Jan 09, 2018 at 04:42:51PM -0500, Frediano Ziglio wrote:
> > 
> > On Mon, Dec 11, 2017 at 10:27:58AM +0000, Frediano Ziglio wrote:
> > > Coverity complaint that this field should be protected by
> > > a mutex as other accesses are with the mutex locked.
> > > Use atomic operation. Not in an hot path in any case.
> > > 
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > ---
> > >  server/stat-file.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/server/stat-file.c b/server/stat-file.c
> > > index 2797fd73..45dece65 100644
> > > --- a/server/stat-file.c
> > > +++ b/server/stat-file.c
> > > @@ -190,7 +190,7 @@ stat_file_add_counter(RedStatFile *stat_file,
> > > StatNodeRef parent, const char *na
> > >          return NULL;
> > >      }
> > >      node = &stat_file->stat->nodes[ref];
> > > -    node->flags |= SPICE_STAT_NODE_FLAG_VALUE;
> > > +    __sync_or_and_fetch(&node->flags, SPICE_STAT_NODE_FLAG_VALUE);
> > 
> > or g_atomic_int_or ?
> > 
> > Christophe
> > 
> 
> Should be the same, beside __sync_or_and_fetch accepts different
> sizes of variable.

I know they should be the same, it's just I find __sync_or_and_fetch()
is a very bad name. g_atomic_int_or() also gives us non-gcc
implementations (Visual Studio and pthread fallback).

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180116/2ee6cb0d/attachment.sig>


More information about the Spice-devel mailing list