[Spice-devel,04/13] spicevmc: Derive SpiceVmcPipeItem from RedPipeItem

Submitted by Jonathon Jongsma on April 13, 2016, 7:37 p.m.

Details

Message ID 1460576282-27544-5-git-send-email-jjongsma@redhat.com
State New
Headers show
Series "Backported patches from refactory branch (April 13)" ( rev: 4 3 2 1 ) in Spice

Commit Message

Jonathon Jongsma April 13, 2016, 7:37 p.m.
From: Christophe Fergeau <cfergeau@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(-)

Patch hide | download patch | download mbox

diff --git a/server/spicevmc.c b/server/spicevmc.c
index 1c41845..66f819c 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,29 +105,16 @@  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_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
                                                                     void *opaque)
 {
-    return spicevmc_pipe_item_ref((SpiceVmcPipeItem *)msg);
+    return red_pipe_item_ref(msg);
 }
 
 static void spicevmc_chardev_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
                                                  void *opaque)
 {
-    spicevmc_pipe_item_unref((SpiceVmcPipeItem *)msg);
+    red_pipe_item_unref(msg);
 }
 
 static RedCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
@@ -147,8 +133,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;
@@ -175,8 +160,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)
@@ -396,7 +381,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);
@@ -472,7 +457,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);
     }

Comments

Same comment as previous patch

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>


On Wed, 2016-04-13 at 14:37 -0500, Jonathon Jongsma wrote:
> From: Christophe Fergeau <cfergeau@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 1c41845..66f819c 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,29 +105,16 @@ 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_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
>                                                                      void
> *opaque)
>  {
> -    return spicevmc_pipe_item_ref((SpiceVmcPipeItem *)msg);
> +    return red_pipe_item_ref(msg);
>  }
>  
>  static void spicevmc_chardev_unref_msg_to_client(RedCharDeviceMsgToClient
> *msg,
>                                                   void *opaque)
>  {
> -    spicevmc_pipe_item_unref((SpiceVmcPipeItem *)msg);
> +    red_pipe_item_unref(msg);
>  }
>  
>  static RedCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
> @@ -147,8 +133,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;
> @@ -175,8 +160,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)
> @@ -396,7 +381,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);
> @@ -472,7 +457,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);
>      }