[Spice-devel] [RFCv5 36/47] server/red_worker: move free from display_channel_send_item to _release_item

Alon Levy alevy at redhat.com
Sun May 8 06:11:32 PDT 2011


---
 server/red_worker.c |   77 +++++++++++++++++++++++++++++---------------------
 1 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index 77b731a..78d2db2 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -8438,86 +8438,69 @@ static void display_channel_send_item(RedChannelClient *rcc, PipeItem *pipe_item
 {
     SpiceMarshaller *m = red_channel_client_get_marshaller(rcc);
     DisplayChannelClient *dcc = RCC_TO_DCC(rcc);
-    DisplayChannel *display_channel = DCC_TO_DC(dcc);
-    RedWorker *worker = display_channel->common.worker;
-    RedRender *render = dcc->common.render;
 
     red_display_reset_send_data(dcc);
     switch (pipe_item->type) {
     case PIPE_ITEM_TYPE_DRAW: {
         Drawable *drawable = SPICE_CONTAINEROF(pipe_item, Drawable, pipe_item);
         marshall_qxl_drawable(rcc, m, drawable);
-        release_drawable(&worker->render, drawable);
+        release_drawable(dcc->common.render, drawable);
         break;
     }
     case PIPE_ITEM_TYPE_INVAL_ONE:
         red_marshall_inval(rcc, m, (CacheItem *)pipe_item);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_STREAM_CREATE: {
         StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, create_item);
         red_display_marshall_stream_start(rcc, m, agent);
-        red_display_release_stream(render, agent);
         break;
     }
     case PIPE_ITEM_TYPE_STREAM_CLIP: {
         StreamClipItem* clip_item = (StreamClipItem *)pipe_item;
         red_display_marshall_stream_clip(rcc, m, clip_item);
-        red_display_release_stream_clip(render, clip_item);
         break;
     }
     case PIPE_ITEM_TYPE_STREAM_DESTROY: {
         StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, destroy_item);
         red_display_marshall_stream_end(rcc, m, agent);
-        red_display_release_stream(render, agent);
         break;
     }
     case PIPE_ITEM_TYPE_UPGRADE:
         red_display_marshall_upgrade(rcc, m, (UpgradeItem *)pipe_item);
-        release_upgrade_item(&worker->render, (UpgradeItem *)pipe_item);
         break;
     case PIPE_ITEM_TYPE_VERB:
         red_marshall_verb(rcc, ((VerbItem*)pipe_item)->verb);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_MIGRATE:
         red_printf("PIPE_ITEM_TYPE_MIGRATE");
         display_channel_marshall_migrate(rcc, m);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_MIGRATE_DATA:
         display_channel_marshall_migrate_data(rcc, m);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_IMAGE:
         red_marshall_image(rcc, m, (ImageItem *)pipe_item);
-        release_image_item((ImageItem *)pipe_item);
         break;
     case PIPE_ITEM_TYPE_PIXMAP_SYNC:
         display_channel_marshall_pixmap_sync(rcc, m);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_PIXMAP_RESET:
         display_channel_marshall_reset_cache(rcc, m);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_INVAL_PALLET_CACHE:
         red_reset_palette_cache(dcc);
         red_marshall_verb(rcc, SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES);
-        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_CREATE_SURFACE: {
         SurfaceCreateItem *surface_create = SPICE_CONTAINEROF(pipe_item, SurfaceCreateItem,
                                                               pipe_item);
         red_marshall_surface_create(rcc, m, &surface_create->surface_create);
-        free(surface_create);
         break;
     }
     case PIPE_ITEM_TYPE_DESTROY_SURFACE: {
         SurfaceDestroyItem *surface_destroy = SPICE_CONTAINEROF(pipe_item, SurfaceDestroyItem,
                                                                 pipe_item);
         red_marshall_surface_destroy(rcc, m, surface_destroy->surface_destroy.surface_id);
-        free(surface_destroy);
         break;
     }
     default:
@@ -8659,7 +8642,7 @@ static void init_render(RedRender *render, RedWorker *worker)
     render->worker = worker;
 }
 
-static void free_render(RedWorker *worker, RedRender *render)
+static void free_render(RedRender *render)
 {
     RingItem *link;
     RingItem *next;
@@ -8787,7 +8770,7 @@ static void display_channel_client_disconnect(RedChannelClient *rcc)
     red_display_destroy_streams(dcc);
     red_channel_client_pipe_clear(rcc); // do this before deleting surfaces
     if (dcc->common.render != &worker->render) {
-        free_render(worker, dcc->common.render);
+        free_render(dcc->common.render);
     } else {
         // if this isn't the last client, free one client's surfaces
         // and let it have the worker's surfaces (this makes it the "primary",
@@ -8809,7 +8792,7 @@ static void display_channel_client_disconnect(RedChannelClient *rcc)
                     DisplayChannelClient, common.base.channel_link);
             }
             ASSERT(other != dcc && other != NULL);
-            free_render(worker, other->common.render);
+            free_render(other->common.render);
             worker->render.dcc = other;
             other->common.render = &worker->render;
         } else {
@@ -9728,7 +9711,7 @@ static void display_channel_hold_pipe_item(RedChannelClient *rcc, PipeItem *item
     }
 }
 
-static void display_channel_release_item(RedChannelClient *rcc, PipeItem *item,
+static void display_channel_release_item(RedChannelClient *rcc, PipeItem *pipe_item,
                                          int item_pushed /* ignored */)
 {
     RedChannel *channel = rcc->channel;
@@ -9737,24 +9720,54 @@ static void display_channel_release_item(RedChannelClient *rcc, PipeItem *item,
     DisplayChannelClient *dcc = RCC_TO_DCC(rcc);
     RedRender *render = dcc->common.render;
 
-    ASSERT(item);
-    switch (item->type) {
-    case PIPE_ITEM_TYPE_DRAW:
-    case PIPE_ITEM_TYPE_STREAM_CREATE:
-        release_drawable(&common->worker->render, SPICE_CONTAINEROF(item, Drawable, pipe_item));
+    ASSERT(pipe_item);
+    switch (pipe_item->type) {
+    case PIPE_ITEM_TYPE_DRAW: {
+        Drawable *drawable = SPICE_CONTAINEROF(pipe_item, Drawable, pipe_item);
+        release_drawable(render, drawable);
         break;
+    }
+    case PIPE_ITEM_TYPE_STREAM_CREATE: {
+        StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, create_item);
+        red_display_release_stream(render, agent);
+        release_drawable(render, SPICE_CONTAINEROF(pipe_item, Drawable, pipe_item));
+        break;
+    }
     case PIPE_ITEM_TYPE_STREAM_CLIP:
-        red_display_release_stream_clip(render, (StreamClipItem *)item);
+        red_display_release_stream_clip(render, (StreamClipItem *)pipe_item);
         break;
+    case PIPE_ITEM_TYPE_STREAM_DESTROY: {
+        StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, destroy_item);
+        red_display_release_stream(render, agent);
+        break;
+    }
     case PIPE_ITEM_TYPE_UPGRADE:
-        release_upgrade_item(&worker->render, (UpgradeItem *)item);
+        release_upgrade_item(&worker->render, (UpgradeItem *)pipe_item);
+        break;
+    case PIPE_ITEM_TYPE_INVAL_ONE:
+    case PIPE_ITEM_TYPE_VERB:
+    case PIPE_ITEM_TYPE_MIGRATE:
+    case PIPE_ITEM_TYPE_MIGRATE_DATA:
+    case PIPE_ITEM_TYPE_PIXMAP_SYNC:
+    case PIPE_ITEM_TYPE_PIXMAP_RESET:
+    case PIPE_ITEM_TYPE_INVAL_PALLET_CACHE:
+        free(pipe_item);
         break;
     case PIPE_ITEM_TYPE_IMAGE:
-        release_image_item((ImageItem *)item);
+        release_image_item((ImageItem *)pipe_item);
         break;
-    case PIPE_ITEM_TYPE_VERB:
-        free(item);
+    case PIPE_ITEM_TYPE_CREATE_SURFACE: {
+        SurfaceCreateItem *surface_create = SPICE_CONTAINEROF(pipe_item, SurfaceCreateItem,
+                                                              pipe_item);
+        free(surface_create);
         break;
+    }
+    case PIPE_ITEM_TYPE_DESTROY_SURFACE: {
+        SurfaceDestroyItem *surface_destroy = SPICE_CONTAINEROF(pipe_item, SurfaceDestroyItem,
+                                                                pipe_item);
+        free(surface_destroy);
+        break;
+    }
     default:
         PANIC("invalid item type");
     }
-- 
1.7.5.1



More information about the Spice-devel mailing list