[PATCH 04/13] spicevmc: Derive SpiceVmcPipeItem from RedPipeItem

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

 



From: Christophe Fergeau <cfergeau@xxxxxxxxxx>

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);
     }
-- 
2.4.11

_______________________________________________
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]