Re: [PATCH 06/20] DrawablePipeItem: use base class for refcounting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> Since PipeItem already implements refcounting, there's no need to
> re-implement it here.
> ---
>  server/dcc.c             | 26 +++++++++-----------------
>  server/dcc.h             |  3 ---
>  server/display-channel.c |  6 ++----
>  3 files changed, 11 insertions(+), 24 deletions(-)
> 
> diff --git a/server/dcc.c b/server/dcc.c
> index 4e450b5..fcef02d 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -274,20 +274,14 @@ static void
> add_drawable_surface_images(DisplayChannelClient *dcc, Drawable *dra
>      dcc_push_surface_image(dcc, drawable->surface_id);
>  }
>  
> -DrawablePipeItem *drawable_pipe_item_ref(DrawablePipeItem *dpi)
> -{
> -    dpi->refs++;
> -    return dpi;
> -}
> -
> -void drawable_pipe_item_unref(DrawablePipeItem *dpi)
> +void drawable_pipe_item_free(PipeItem *item)
>  {
> +    DrawablePipeItem *dpi = SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item);
>      DisplayChannel *display = DCC_TO_DC(dpi->dcc);
>  
> -    if (--dpi->refs != 0)
> -        return;
> +    g_return_if_fail(item->refcount == 0);
>  

Would prefer an assert here but just an opinion.

> -    spice_warn_if_fail(!ring_item_is_linked(&dpi->dpi_pipe_item.link));
> +    spice_warn_if_fail(!ring_item_is_linked(&item->link));
>      spice_warn_if_fail(!ring_item_is_linked(&dpi->base));
>      display_channel_drawable_unref(display, dpi->drawable);
>      free(dpi);
> @@ -302,8 +296,8 @@ static DrawablePipeItem
> *drawable_pipe_item_new(DisplayChannelClient *dcc, Drawa
>      dpi->dcc = dcc;
>      ring_item_init(&dpi->base);
>      ring_add(&drawable->pipes, &dpi->base);
> -    pipe_item_init(&dpi->dpi_pipe_item, PIPE_ITEM_TYPE_DRAW);
> -    dpi->refs++;
> +    pipe_item_init_full(&dpi->dpi_pipe_item, PIPE_ITEM_TYPE_DRAW,
> +                        (GDestroyNotify)drawable_pipe_item_free);
>      drawable->refs++;
>      return dpi;
>  }
> @@ -1606,7 +1600,8 @@ static void
> release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
>  
>      switch (item->type) {
>      case PIPE_ITEM_TYPE_DRAW:
> -        drawable_pipe_item_unref(SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item));
> +    case PIPE_ITEM_TYPE_IMAGE:
> +        pipe_item_unref(item);
>          break;
>      case PIPE_ITEM_TYPE_STREAM_CLIP:
>          stream_clip_item_unref(dcc, (StreamClipItem *)item);
> @@ -1614,9 +1609,6 @@ static void
> release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
>      case PIPE_ITEM_TYPE_UPGRADE:
>          upgrade_item_unref(display, (UpgradeItem *)item);
>          break;
> -    case PIPE_ITEM_TYPE_IMAGE:
> -        pipe_item_unref(item);
> -        break;
>      case PIPE_ITEM_TYPE_GL_SCANOUT:
>      case PIPE_ITEM_TYPE_GL_DRAW:
>      case PIPE_ITEM_TYPE_VERB:
> @@ -1645,7 +1637,7 @@ static void
> release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
>      case PIPE_ITEM_TYPE_DRAW: {
>          DrawablePipeItem *dpi = SPICE_CONTAINEROF(item, DrawablePipeItem,
>          dpi_pipe_item);
>          ring_remove(&dpi->base);
> -        drawable_pipe_item_unref(dpi);
> +        pipe_item_unref(item);
>          break;
>      }
>      case PIPE_ITEM_TYPE_STREAM_CREATE: {
> diff --git a/server/dcc.h b/server/dcc.h
> index 3d7870b..e8354e2 100644
> --- a/server/dcc.h
> +++ b/server/dcc.h
> @@ -157,9 +157,6 @@ typedef struct DrawablePipeItem {
>      uint8_t refs;
>  } DrawablePipeItem;
>  
> -void                       drawable_pipe_item_unref
> (DrawablePipeItem *dpi);
> -DrawablePipeItem*          drawable_pipe_item_ref
> (DrawablePipeItem *dpi);
> -
>  DisplayChannelClient*      dcc_new
>  (DisplayChannel *display,
>                                                                        RedClient
>                                                                        *client,
>                                                                        RedsStream
>                                                                        *stream,
> diff --git a/server/display-channel.c b/server/display-channel.c
> index ac10724..4d339f5 100644
> --- a/server/display-channel.c
> +++ b/server/display-channel.c
> @@ -1971,7 +1971,8 @@ static void hold_item(RedChannelClient *rcc, PipeItem
> *item)
>  
>      switch (item->type) {
>      case PIPE_ITEM_TYPE_DRAW:
> -        drawable_pipe_item_ref(SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item));
> +    case PIPE_ITEM_TYPE_IMAGE:
> +        pipe_item_ref(item);
>          break;
>      case PIPE_ITEM_TYPE_STREAM_CLIP:
>          ((StreamClipItem *)item)->refs++;
> @@ -1979,9 +1980,6 @@ static void hold_item(RedChannelClient *rcc, PipeItem
> *item)
>      case PIPE_ITEM_TYPE_UPGRADE:
>          ((UpgradeItem *)item)->refs++;
>          break;
> -    case PIPE_ITEM_TYPE_IMAGE:
> -        pipe_item_ref(item);
> -        break;
>      default:
>          spice_warn_if_reached();
>      }

Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]