[PATCH 06/15] Replace RedsPrivate::char_devs_state with a GList

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

 



From: Christophe Fergeau <cfergeau@xxxxxxxxxx>

The code was introducing an intermediate SpiceCharDevStateItem type to
hold linked list elements, resulting in a memory handling behaviour very
similar to a GList. Using GList directly makes the code shorter and more
readable.
---
 server/reds-private.h |  7 +------
 server/reds.c         | 41 ++++++++++-------------------------------
 2 files changed, 11 insertions(+), 37 deletions(-)

diff --git a/server/reds-private.h b/server/reds-private.h
index 6bd6878..b2afc6b 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -125,11 +125,6 @@ typedef struct RedsMigWaitDisconnectClient {
     RedClient *client;
 } RedsMigWaitDisconnectClient;
 
-typedef struct SpiceCharDeviceStateItem {
-    RingItem link;
-    SpiceCharDeviceState *st;
-} SpiceCharDeviceStateItem;
-
 /* Intermediate state for on going monitors config message from a single
  * client, being passed to the guest */
 typedef struct RedsClientMonitorsConfig {
@@ -187,7 +182,7 @@ struct RedsState {
     SpiceTimer *mig_timer;
 
     int vm_running;
-    Ring char_devs_states; /* list of SpiceCharDeviceStateItem */
+    GList *char_devices; /* list of SpiceCharDeviceState */
     int seamless_migration_enabled; /* command line arg */
     int keepalive_timeout;
 
diff --git a/server/reds.c b/server/reds.c
index 08913e8..0a2f6f9 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3088,28 +3088,13 @@ SPICE_GNUC_VISIBLE const char** spice_server_char_device_recognized_subtypes(voi
 
 static void reds_char_device_add_state(RedsState *reds, SpiceCharDeviceState *st)
 {
-    SpiceCharDeviceStateItem *item = spice_new0(SpiceCharDeviceStateItem, 1);
-
-    item->st = st;
-
-    ring_add(&reds->char_devs_states, &item->link);
+    reds->char_devices = g_list_append(reds->char_devices, st);
 }
 
 static void reds_char_device_remove_state(RedsState *reds, SpiceCharDeviceState *st)
 {
-    RingItem *item;
-
-    RING_FOREACH(item, &reds->char_devs_states) {
-        SpiceCharDeviceStateItem *st_item;
-
-        st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link);
-        if (st_item->st == st) {
-            ring_remove(item);
-            free(st_item);
-            return;
-        }
-    }
-    spice_error("char dev state not found %p", st);
+    g_warn_if_fail(g_list_find(reds->char_devices, st) != NULL);
+    reds->char_devices = g_list_remove(reds->char_devices, st);
 }
 
 void reds_on_char_device_state_destroy(RedsState *reds, SpiceCharDeviceState *dev)
@@ -3371,7 +3356,7 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
     reds->main_dispatcher = main_dispatcher_new(reds, reds->core);
     ring_init(&reds->channels);
     ring_init(&reds->mig_target_clients);
-    ring_init(&reds->char_devs_states);
+    reds->char_devices = NULL;
     ring_init(&reds->mig_wait_disconnect_clients);
     reds->vm_running = TRUE; /* for backward compatibility */
 
@@ -3992,28 +3977,22 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_switch(SpiceServer *reds)
 
 SPICE_GNUC_VISIBLE void spice_server_vm_start(SpiceServer *reds)
 {
-    RingItem *item;
+    GList *it;
 
     reds->vm_running = TRUE;
-    RING_FOREACH(item, &reds->char_devs_states) {
-        SpiceCharDeviceStateItem *st_item;
-
-        st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link);
-        spice_char_device_start(st_item->st);
+    for (it = reds->char_devices; it != NULL; it = it->next) {
+        spice_char_device_start((SpiceCharDeviceState *)it->data);
     }
     reds_on_vm_start(reds);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_vm_stop(SpiceServer *reds)
 {
-    RingItem *item;
+    GList *it;
 
     reds->vm_running = FALSE;
-    RING_FOREACH(item, &reds->char_devs_states) {
-        SpiceCharDeviceStateItem *st_item;
-
-        st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link);
-        spice_char_device_stop(st_item->st);
+    for (it = reds->char_devices; it != NULL; it = it->next) {
+        spice_char_device_stop((SpiceCharDeviceState *)it->data);
     }
     reds_on_vm_stop(reds);
 }
-- 
2.5.0

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