[Spice-devel] [PATCH 08/14] spicevmc: Derive SpiceVmcPipeItem from RedPipeItem

Jonathon Jongsma jjongsma at redhat.com
Mon Apr 11 22:00:02 UTC 2016


On Thu, 2016-04-07 at 17:11 -0500, Jonathon Jongsma wrote:
> From: Christophe Fergeau <cfergeau at redhat.com>
> 
> This allows to reuse red_pipe_item_{ref, unref} rather than
> reimplementing them in spicevmc.c
> ---
>  server/spicevmc.c | 31 ++++++++-----------------------
>  1 file changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index b6ba19d..7294c2c 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -43,8 +43,7 @@
>  #define BUF_SIZE (64 * 1024 + 32)
>  
>  typedef struct SpiceVmcPipeItem {
> -    PipeItem base;
> -    uint32_t refs;
> +    RedPipeItem base;
>  
>      /* writes which don't fit this will get split, this is not a problem */
>      uint8_t buf[BUF_SIZE];
> @@ -106,19 +105,6 @@ enum {
>      PIPE_ITEM_TYPE_PORT_EVENT,
>  };
>  
> -static SpiceVmcPipeItem *spicevmc_pipe_item_ref(SpiceVmcPipeItem *item)
> -{
> -    item->refs++;
> -    return item;
> -}
> -
> -static void spicevmc_pipe_item_unref(SpiceVmcPipeItem *item)
> -{
> -    if (!--item->refs) {
> -        free(item);
> -    }
> -}
> -
>  static RedCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
>                                                                      void
> *opaque)
>  {
> @@ -135,8 +121,7 @@ static RedCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharDev
>  
>      if (!state->pipe_item) {
>          msg_item = spice_new0(SpiceVmcPipeItem, 1);
> -        msg_item->refs = 1;
> -        pipe_item_init(&msg_item->base, PIPE_ITEM_TYPE_SPICEVMC_DATA);
> +        red_pipe_item_init(&msg_item->base, PIPE_ITEM_TYPE_SPICEVMC_DATA,
> free);
>      } else {
>          spice_assert(state->pipe_item->buf_used == 0);
>          msg_item = state->pipe_item;
> @@ -163,8 +148,8 @@ static void
> spicevmc_chardev_send_msg_to_client(RedCharDeviceMsgToClient *msg,
>      SpiceVmcPipeItem *vmc_msg = msg;
>  
>      spice_assert(state->rcc->client == client);
> -    spicevmc_pipe_item_ref(vmc_msg);
> -    red_channel_client_pipe_add_push(state->rcc, &vmc_msg->base);
> +    red_pipe_item_ref(vmc_msg);
> +    red_channel_client_pipe_add_push(state->rcc, (PipeItem *)vmc_msg);
>  }
>  
>  static void spicevmc_port_send_init(RedChannelClient *rcc)
> @@ -384,7 +369,7 @@ static void
> spicevmc_red_channel_send_data(RedChannelClient *rcc,
>                                             SpiceMarshaller *m,
>                                             PipeItem *item)
>  {
> -    SpiceVmcPipeItem *i = SPICE_CONTAINEROF(item, SpiceVmcPipeItem, base);
> +    SpiceVmcPipeItem *i = SPICE_CONTAINEROF(item, SpiceVmcPipeItem,
> base.parent);
>  
>      red_channel_client_init_send_data(rcc, SPICE_MSG_SPICEVMC_DATA, item);
>      spice_marshaller_add_ref(m, i->buf, i->buf_used);
> @@ -460,7 +445,7 @@ static void
> spicevmc_red_channel_release_pipe_item(RedChannelClient *rcc,
>      PipeItem *item, int item_pushed)
>  {
>      if (item->type == PIPE_ITEM_TYPE_SPICEVMC_DATA) {
> -        spicevmc_pipe_item_unref((SpiceVmcPipeItem *)item);
> +        red_pipe_item_unref(item);
>      } else {
>          free(item);
>      }
> @@ -602,8 +587,8 @@
> red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass)
>      RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
>  
>      char_dev_class->read_one_msg_from_device =
> spicevmc_chardev_read_msg_from_dev;
> -    char_dev_class->ref_msg_to_client =
> (RedCharDeviceRefMsgToClient)spicevmc_pipe_item_ref;
> -    char_dev_class->unref_msg_to_client =
> (RedCharDeviceUnrefMsgToClient)spicevmc_pipe_item_unref;
> +    char_dev_class->ref_msg_to_client =
> (RedCharDeviceRefMsgToClient)red_pipe_item_ref;
> +    char_dev_class->unref_msg_to_client =
> (RedCharDeviceUnrefMsgToClient)red_pipe_item_unref;
>      char_dev_class->send_msg_to_client = spicevmc_chardev_send_msg_to_client;
>      char_dev_class->send_tokens_to_client =
> spicevmc_char_dev_send_tokens_to_client;
>      char_dev_class->remove_client = spicevmc_char_dev_remove_client;

Same comment about casting functions. Otherwise good.

Reviewed-by: Jonathon Jongsma <jjongsma at redhat.com>



More information about the Spice-devel mailing list