[Spice-devel] [PATCH spice-gtk] spice-channel: Use atomic operations for SpiceMsgIn::refcount

Victor Toso victortoso at redhat.com
Tue Apr 17 13:34:57 UTC 2018


On Tue, Apr 17, 2018 at 01:32:53PM +0100, Frediano Ziglio wrote:
> This structure is potentially used in multiple thread.
> Currently in Gstreamer thread using streaming data and coroutine
> thread.

But only GStreamer uses another thread, so this might be
suboptimal for all other channels.

> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> I would avoid the atomic penalty but better safe then sorry
> ---
>  src/spice-channel-priv.h | 2 +-
>  src/spice-channel.c      | 5 ++---
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/src/spice-channel-priv.h b/src/spice-channel-priv.h
> index b431037..706df9f 100644
> --- a/src/spice-channel-priv.h
> +++ b/src/spice-channel-priv.h
> @@ -55,7 +55,7 @@ struct _SpiceMsgOut {
>  };
>  
>  struct _SpiceMsgIn {
> -    int                   refcount;
> +    gint                  refcount;
>      SpiceChannel          *channel;
>      uint8_t               header[MAX_SPICE_DATA_HEADER_SIZE];
>      uint8_t               *data;
> diff --git a/src/spice-channel.c b/src/spice-channel.c
> index 7e3e3b7..49897b7 100644
> --- a/src/spice-channel.c
> +++ b/src/spice-channel.c
> @@ -531,7 +531,7 @@ void spice_msg_in_ref(SpiceMsgIn *in)
>  {
>      g_return_if_fail(in != NULL);
>  
> -    in->refcount++;
> +    g_atomic_int_inc(&in->refcount);
>  }
>  
>  G_GNUC_INTERNAL
> @@ -539,8 +539,7 @@ void spice_msg_in_unref(SpiceMsgIn *in)
>  {
>      g_return_if_fail(in != NULL);
>  
> -    in->refcount--;
> -    if (in->refcount > 0)
> +    if (!g_atomic_int_dec_and_test(&in->refcount))
>          return;
>      if (in->parsed)
>          in->pfree(in->parsed);
> -- 
> 2.14.3
> 
> _______________________________________________
> 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: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180417/84e60701/attachment.sig>


More information about the Spice-devel mailing list