Re: [PATCH 09/18] worker: move dcc_release_item

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

 



On Mon, 2015-11-23 at 17:01 +0000, Frediano Ziglio wrote:
> From: Marc-André Lureau <marcandre.lureau@xxxxxxxxx>
> 
> ---
>  server/dcc.c             | 124 ++++++++++++++++++++++++++++++++++++++++++
>  server/dcc.h             |   3 ++
>  server/display-channel.h |   7 +++
>  server/red_worker.c      | 136 +---------------------------------------------
> -
>  4 files changed, 136 insertions(+), 134 deletions(-)
> 
> diff --git a/server/dcc.c b/server/dcc.c
> index 5be3769..5d666cb 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -1394,3 +1394,127 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc,
> uint32_t size, void *mess
>      red_channel_client_ack_zero_messages_window(RED_CHANNEL_CLIENT(dcc));
>      return TRUE;
>  }
> +
> +static void image_item_unref(ImageItem *item)
> +{
> +    if (--item->refs != 0)
> +        return;
> +
> +    free(item);
> +}
> +
> +static void upgrade_item_unref(DisplayChannel *display, UpgradeItem *item)
> +{
> +    if (--item->refs != 0)
> +        return;
> +
> +    display_channel_drawable_unref(display, item->drawable);
> +    free(item->rects);
> +    free(item);
> +}
> +
> +static void release_item_after_push(DisplayChannelClient *dcc, PipeItem
> *item)
> +{
> +    DisplayChannel *display = DCC_TO_DC(dcc);
> +
> +    switch (item->type) {
> +    case PIPE_ITEM_TYPE_DRAW:
> +        drawable_pipe_item_unref(SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item));
> +        break;
> +    case PIPE_ITEM_TYPE_STREAM_CLIP:
> +        stream_clip_item_unref(dcc, (StreamClipItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_UPGRADE:
> +        upgrade_item_unref(display, (UpgradeItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_IMAGE:
> +        image_item_unref((ImageItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_VERB:
> +        free(item);
> +        break;
> +    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
> +        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
> +                                                            
>  MonitorsConfigItem, pipe_item);
> +        monitors_config_unref(monconf_item->monitors_config);
> +        free(item);
> +        break;
> +    }
> +    default:
> +        spice_critical("invalid item type");
> +    }
> +}
> +
> +// TODO: share code between before/after_push since most of the items need
> the same
> +// release
> +static void release_item_before_push(DisplayChannelClient *dcc, PipeItem
> *item)
> +{
> +    DisplayChannel *display = DCC_TO_DC(dcc);
> +
> +    spice_debug("item.type: %d", item->type);
> +    switch (item->type) {
> +    case PIPE_ITEM_TYPE_DRAW: {
> +        DrawablePipeItem *dpi = SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item);
> +        ring_remove(&dpi->base);
> +        drawable_pipe_item_unref(dpi);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_STREAM_CREATE: {
> +        StreamAgent *agent = SPICE_CONTAINEROF(item, StreamAgent,
> create_item);
> +        stream_agent_unref(display, agent);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_STREAM_CLIP:
> +        stream_clip_item_unref(dcc, (StreamClipItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_STREAM_DESTROY: {
> +        StreamAgent *agent = SPICE_CONTAINEROF(item, StreamAgent,
> destroy_item);
> +        stream_agent_unref(display, agent);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_UPGRADE:
> +        upgrade_item_unref(display, (UpgradeItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_IMAGE:
> +        image_item_unref((ImageItem *)item);
> +        break;
> +    case PIPE_ITEM_TYPE_CREATE_SURFACE: {
> +        SurfaceCreateItem *surface_create = SPICE_CONTAINEROF(item,
> SurfaceCreateItem,
> +                                                              pipe_item);
> +        free(surface_create);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_DESTROY_SURFACE: {
> +        SurfaceDestroyItem *surface_destroy = SPICE_CONTAINEROF(item,
> SurfaceDestroyItem,
> +                                                                pipe_item);
> +        free(surface_destroy);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
> +        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
> +                                                            
>  MonitorsConfigItem, pipe_item);
> +        monitors_config_unref(monconf_item->monitors_config);
> +        free(item);
> +        break;
> +    }
> +    case PIPE_ITEM_TYPE_INVAL_ONE:
> +    case PIPE_ITEM_TYPE_VERB:
> +    case PIPE_ITEM_TYPE_MIGRATE_DATA:
> +    case PIPE_ITEM_TYPE_PIXMAP_SYNC:
> +    case PIPE_ITEM_TYPE_PIXMAP_RESET:
> +    case PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE:
> +    case PIPE_ITEM_TYPE_STREAM_ACTIVATE_REPORT:
> +        free(item);
> +        break;
> +    default:
> +        spice_critical("invalid item type");
> +    }
> +}
> +
> +void dcc_release_item(DisplayChannelClient *dcc, PipeItem *item, int
> item_pushed)
> +{
> +    if (item_pushed)
> +        release_item_after_push(dcc, item);
> +    else
> +        release_item_before_push(dcc, item);
> +}
> diff --git a/server/dcc.h b/server/dcc.h
> index 94b9195..62261e8 100644
> --- a/server/dcc.h
> +++ b/server/dcc.h
> @@ -195,6 +195,9 @@ void                       dcc_append_drawable            
>            (DisplayCha
>  void                       dcc_add_drawable_after                   
>  (DisplayChannelClient *dcc,
>                                                                       
>  Drawable *drawable,
>                                                                       
>  PipeItem *pos);
> +void                       dcc_release_item                         
>  (DisplayChannelClient *dcc,
> +                                                                     
>  PipeItem *item,
> +                                                                      int
> item_pushed);
>  
>  typedef struct compress_send_data_t {
>      void*    comp_buf;
> diff --git a/server/display-channel.h b/server/display-channel.h
> index e26a1d8..e624a6b 100644
> --- a/server/display-channel.h
> +++ b/server/display-channel.h
> @@ -243,6 +243,13 @@ typedef struct SurfaceDestroyItem {
>      PipeItem pipe_item;
>  } SurfaceDestroyItem;
>  
> +typedef struct UpgradeItem {
> +    PipeItem base;
> +    int refs;
> +    Drawable *drawable;
> +    SpiceClipRects *rects;
> +} UpgradeItem;
> +
>  
>  void                       display_channel_free_some                
>  (DisplayChannel *display);
>  void                       display_channel_set_stream_video         
>  (DisplayChannel *display,
> diff --git a/server/red_worker.c b/server/red_worker.c
> index 47b6b82..ac1ef0c 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -85,13 +85,6 @@ struct SpiceWatch {
>  
>  #define MAX_PIPE_SIZE 50
>  
> -typedef struct UpgradeItem {
> -    PipeItem base;
> -    int refs;
> -    Drawable *drawable;
> -    SpiceClipRects *rects;
> -} UpgradeItem;
> -
>  struct RedWorker {
>      pthread_t thread;
>      clockid_t clockid;
> @@ -148,10 +141,6 @@ static void display_channel_draw(DisplayChannel *display,
> const SpiceRect *area,
>  static void display_channel_draw_till(DisplayChannel *display, const
> SpiceRect *area, int surface_id,
>                                        Drawable *last);
>  static inline void display_begin_send_message(RedChannelClient *rcc);
> -static void
> display_channel_client_release_item_before_push(DisplayChannelClient *dcc,
> -                                                            PipeItem *item);
> -static void
> display_channel_client_release_item_after_push(DisplayChannelClient *dcc,
> -                                                           PipeItem *item);
>  static void red_create_surface(DisplayChannel *display, uint32_t surface_id,
> uint32_t width,
>                                 uint32_t height, int32_t stride, uint32_t
> format,
>                                 void *line_0, int data_is_valid, int
> send_client);
> @@ -238,23 +227,6 @@ void red_pipes_remove_drawable(Drawable *drawable)
>      }
>  }
>  
> -static void release_image_item(ImageItem *item)
> -{
> -    if (!--item->refs) {
> -        free(item);
> -    }
> -}
> -
> -static void upgrade_item_unref(DisplayChannel *display, UpgradeItem *item)
> -{
> -    if (--item->refs != 0)
> -        return;
> -
> -    display_channel_drawable_unref(display, item->drawable);
> -    free(item->rects);
> -    free(item);
> -}
> -
>  static uint8_t *common_alloc_recv_buf(RedChannelClient *rcc, uint16_t type,
> uint32_t size)
>  {
>      CommonChannel *common = SPICE_CONTAINEROF(rcc->channel, CommonChannel,
> base);
> @@ -3956,7 +3928,7 @@ static void display_channel_send_item(RedChannelClient
> *rcc, PipeItem *pipe_item
>          spice_error("invalid pipe item type");
>      }
>  
> -    display_channel_client_release_item_before_push(dcc, pipe_item);
> +    dcc_release_item(dcc, pipe_item, FALSE);
>  
>      // a message is pending
>      if (red_channel_client_send_message_pending(rcc)) {
> @@ -4477,116 +4449,12 @@ static void
> display_channel_hold_pipe_item(RedChannelClient *rcc, PipeItem *item
>      }
>  }
>  
> -static void
> display_channel_client_release_item_after_push(DisplayChannelClient *dcc,
> -                                                           PipeItem *item)
> -{
> -    DisplayChannel *display = DCC_TO_DC(dcc);
> -
> -    switch (item->type) {
> -    case PIPE_ITEM_TYPE_DRAW:
> -        drawable_pipe_item_unref(SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item));
> -        break;
> -    case PIPE_ITEM_TYPE_STREAM_CLIP:
> -        stream_clip_item_unref(dcc, (StreamClipItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_UPGRADE:
> -        upgrade_item_unref(display, (UpgradeItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_IMAGE:
> -        release_image_item((ImageItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_VERB:
> -        free(item);
> -        break;
> -    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
> -        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
> -                                                            
>  MonitorsConfigItem, pipe_item);
> -        monitors_config_unref(monconf_item->monitors_config);
> -        free(item);
> -        break;
> -    }
> -    default:
> -        spice_critical("invalid item type");
> -    }
> -}
> -
> -// TODO: share code between before/after_push since most of the items need
> the same
> -// release
> -static void
> display_channel_client_release_item_before_push(DisplayChannelClient *dcc,
> -                                                            PipeItem *item)
> -{
> -    DisplayChannel *display = DCC_TO_DC(dcc);
> -
> -    switch (item->type) {
> -    case PIPE_ITEM_TYPE_DRAW: {
> -        DrawablePipeItem *dpi = SPICE_CONTAINEROF(item, DrawablePipeItem,
> dpi_pipe_item);
> -        ring_remove(&dpi->base);
> -        drawable_pipe_item_unref(dpi);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_STREAM_CREATE: {
> -        StreamAgent *agent = SPICE_CONTAINEROF(item, StreamAgent,
> create_item);
> -        stream_agent_unref(display, agent);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_STREAM_CLIP:
> -        stream_clip_item_unref(dcc, (StreamClipItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_STREAM_DESTROY: {
> -        StreamAgent *agent = SPICE_CONTAINEROF(item, StreamAgent,
> destroy_item);
> -        stream_agent_unref(display, agent);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_UPGRADE:
> -        upgrade_item_unref(display, (UpgradeItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_IMAGE:
> -        release_image_item((ImageItem *)item);
> -        break;
> -    case PIPE_ITEM_TYPE_CREATE_SURFACE: {
> -        SurfaceCreateItem *surface_create = SPICE_CONTAINEROF(item,
> SurfaceCreateItem,
> -                                                              pipe_item);
> -        free(surface_create);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_DESTROY_SURFACE: {
> -        SurfaceDestroyItem *surface_destroy = SPICE_CONTAINEROF(item,
> SurfaceDestroyItem,
> -                                                                pipe_item);
> -        free(surface_destroy);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
> -        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
> -                                                            
>  MonitorsConfigItem, pipe_item);
> -        monitors_config_unref(monconf_item->monitors_config);
> -        free(item);
> -        break;
> -    }
> -    case PIPE_ITEM_TYPE_INVAL_ONE:
> -    case PIPE_ITEM_TYPE_VERB:
> -    case PIPE_ITEM_TYPE_MIGRATE_DATA:
> -    case PIPE_ITEM_TYPE_PIXMAP_SYNC:
> -    case PIPE_ITEM_TYPE_PIXMAP_RESET:
> -    case PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE:
> -    case PIPE_ITEM_TYPE_STREAM_ACTIVATE_REPORT:
> -        free(item);
> -        break;
> -    default:
> -        spice_critical("invalid item type");
> -    }
> -}
> -
>  static void display_channel_release_item(RedChannelClient *rcc, PipeItem
> *item, int item_pushed)
>  {
>      DisplayChannelClient *dcc = RCC_TO_DCC(rcc);
>  
>      spice_assert(item);
> -    if (item_pushed) {
> -        display_channel_client_release_item_after_push(dcc, item);
> -    } else {
> -        spice_debug("not pushed (%d)", item->type);
> -        display_channel_client_release_item_before_push(dcc, item);
> -    }
> +    dcc_release_item(dcc, item, item_pushed);
>  }
>  
>  static void display_channel_create(RedWorker *worker, int migrate, int
> stream_video,


Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://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]