[Spice-devel] [PATCH 04/20] SpiceVmcPipeItem: use base PipeItem for ref counting

Jonathon Jongsma jjongsma at redhat.com
Thu Apr 14 21:50:06 UTC 2016


From: Christophe Fergeau <cfergeau at redhat.com>

This allows to reuse pipe_item_{ref, unref} rather than
reimplementing them in spicevmc.c
---
 server/spicevmc.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/server/spicevmc.c b/server/spicevmc.c
index 1c41845..dececc5 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -44,7 +44,6 @@
 
 typedef struct SpiceVmcPipeItem {
     PipeItem base;
-    uint32_t refs;
 
     /* 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 pipe_item_ref(msg);
 }
 
 static void spicevmc_chardev_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
                                                  void *opaque)
 {
-    spicevmc_pipe_item_unref((SpiceVmcPipeItem *)msg);
+    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);
+        pipe_item_init_full(&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);
+    pipe_item_ref(vmc_msg);
+    red_channel_client_pipe_add_push(state->rcc, (PipeItem *)vmc_msg);
 }
 
 static void spicevmc_port_send_init(RedChannelClient *rcc)
@@ -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);
+        pipe_item_unref(item);
     } else {
         free(item);
     }
-- 
2.4.11



More information about the Spice-devel mailing list