[Spice-devel] [PATCH] red-channel: make red_client_{ref, unref} thread safe

Christophe Fergeau cfergeau at redhat.com
Tue Apr 12 13:10:53 UTC 2016


On Tue, Apr 12, 2016 at 01:46:22PM +0100, Frediano Ziglio wrote:
> These function are called on both side of dispatcher so the
> increment/decrement of the counter is done in multiple thread.
> 
> This fix https://bugzilla.redhat.com/show_bug.cgi?id=1253375.

"This fixes ..."
More details about the race which is occurring/the crash would be useful
to have in the log I think.

Apart from this,
Acked-by: Christophe Fergeau <cfergeau at redhat.com>

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/red-channel.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/server/red-channel.c b/server/red-channel.c
> index d8f1d27..cfddea0 100644
> --- a/server/red-channel.c
> +++ b/server/red-channel.c
> @@ -2064,13 +2064,13 @@ RedClient *red_client_new(RedsState *reds, int migrated)
>  RedClient *red_client_ref(RedClient *client)
>  {
>      spice_assert(client);
> -    client->refs++;
> +    g_atomic_int_inc(&client->refs);
>      return client;
>  }
>  
>  RedClient *red_client_unref(RedClient *client)
>  {
> -    if (!--client->refs) {
> +    if (g_atomic_int_dec_and_test(&client->refs)) {
>          spice_debug("release client=%p", client);
>          pthread_mutex_destroy(&client->lock);
>          free(client);
> -- 
> 2.5.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160412/da7aeefa/attachment.sig>


More information about the Spice-devel mailing list