diff options
author | Jonathon Jongsma <jjongsma@redhat.com> | 2015-10-05 14:22:31 -0500 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2015-12-14 11:42:40 +0000 |
commit | 10310df22c30321a21b1ff395ce0a4a63d59fb41 (patch) | |
tree | fcb577ce81fcd7783c08159f39286d74570b9fbf | |
parent | a6dd1bc3a405cbcd9399e2fd2b0ff1179cd0ef84 (diff) |
c5ea9dabba8d5a37734af282636b3974f7d92764 Change RedCharDevicePrivate::clients to GListdaily-20151214
More Ring cleanup
-rw-r--r-- | server/char-device.c | 72 |
1 files changed, 30 insertions, 42 deletions
diff --git a/server/char-device.c b/server/char-device.c index 0c35b94e..7ffeef75 100644 --- a/server/char-device.c +++ b/server/char-device.c @@ -31,7 +31,6 @@ typedef struct SpiceCharDeviceClientState SpiceCharDeviceClientState; struct SpiceCharDeviceClientState { - RingItem link; SpiceCharDeviceState *dev; RedClient *client; int do_flow_control; @@ -58,8 +57,7 @@ struct RedCharDevicePrivate { SpiceTimer *write_to_dev_timer; uint64_t num_self_tokens; - Ring clients; /* list of SpiceCharDeviceClientState */ - uint32_t num_clients; + GList *clients; /* list of SpiceCharDeviceClientState */ uint64_t client_tokens_interval; /* frequency of returning tokens to the client */ SpiceCharDeviceInstance *sin; @@ -219,8 +217,7 @@ static void spice_char_device_client_free(SpiceCharDeviceState *dev, dev->priv->cur_write_buf->client = NULL; } - dev->priv->num_clients--; - ring_remove(&dev_client->link); + dev->priv->clients = g_list_remove(dev->priv->clients, dev_client); free(dev_client); } @@ -234,12 +231,11 @@ static void spice_char_device_handle_client_overflow(SpiceCharDeviceClientState static SpiceCharDeviceClientState *spice_char_device_client_find(SpiceCharDeviceState *dev, RedClient *client) { - RingItem *item; + GList *item; - RING_FOREACH(item, &dev->priv->clients) { - SpiceCharDeviceClientState *dev_client; + for (item = dev->priv->clients; item != NULL; item = item->next) { + SpiceCharDeviceClientState *dev_client = item->data; - dev_client = SPICE_CONTAINEROF(item, SpiceCharDeviceClientState, link); if (dev_client->client == client) { return dev_client; } @@ -265,13 +261,11 @@ static int spice_char_device_can_send_to_client(SpiceCharDeviceClientState *dev_ static uint64_t spice_char_device_max_send_tokens(SpiceCharDeviceState *dev) { - RingItem *item; + GList *item; uint64_t max = 0; - RING_FOREACH(item, &dev->priv->clients) { - SpiceCharDeviceClientState *dev_client; - - dev_client = SPICE_CONTAINEROF(item, SpiceCharDeviceClientState, link); + for (item = dev->priv->clients; item != NULL; item = item->next) { + SpiceCharDeviceClientState *dev_client = item->data; if (!dev_client->do_flow_control) { max = ~0; @@ -307,12 +301,13 @@ static void spice_char_device_add_msg_to_client_queue(SpiceCharDeviceClientState static void spice_char_device_send_msg_to_clients(SpiceCharDeviceState *dev, RedPipeItem *msg) { - RingItem *item, *next; + GList *item, *next; - RING_FOREACH_SAFE(item, next, &dev->priv->clients) { - SpiceCharDeviceClientState *dev_client; + item = dev->priv->clients; + while (item) { + next = item->next; + SpiceCharDeviceClientState *dev_client = item->data; - dev_client = SPICE_CONTAINEROF(item, SpiceCharDeviceClientState, link); if (spice_char_device_can_send_to_client(dev_client)) { dev_client->num_send_tokens--; spice_assert(g_queue_is_empty(dev_client->send_queue)); @@ -322,6 +317,7 @@ static void spice_char_device_send_msg_to_clients(SpiceCharDeviceState *dev, } else { spice_char_device_add_msg_to_client_queue(dev_client, msg); } + item = next; } } @@ -350,7 +346,7 @@ static int spice_char_device_read_from_device(SpiceCharDeviceState *dev) * Reading from the device only in case at least one of the clients have a free token. * All messages will be discarded if no client is attached to the device */ - while ((max_send_tokens || ring_is_empty(&dev->priv->clients)) && dev->priv->running) { + while ((max_send_tokens || (dev->priv->clients == NULL)) && dev->priv->running) { RedPipeItem *msg; msg = spice_char_device_read_one_msg_from_device(dev); @@ -767,7 +763,7 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev, spice_assert(dev); spice_assert(client); - if (wait_for_migrate_data && (dev->priv->num_clients > 0 || dev->priv->active)) { + if (wait_for_migrate_data && (dev->priv->clients != NULL || dev->priv->active)) { spice_warning("can't restore device %p from migration data. The device " "has already been active", dev); return FALSE; @@ -781,8 +777,7 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev, num_client_tokens, num_send_tokens); dev_client->dev = dev; - ring_add(&dev->priv->clients, &dev_client->link); - dev->priv->num_clients++; + dev->priv->clients = g_list_prepend(dev->priv->clients, dev_client); /* Now that we have a client, forward any pending device data */ spice_char_device_wakeup(dev); return TRUE; @@ -802,12 +797,12 @@ void spice_char_device_client_remove(SpiceCharDeviceState *dev, } spice_char_device_client_free(dev, dev_client); if (dev->priv->wait_for_migrate_data) { - spice_assert(dev->priv->num_clients == 0); + spice_assert(dev->priv->clients == NULL); dev->priv->wait_for_migrate_data = FALSE; spice_char_device_read_from_device(dev); } - if (dev->priv->num_clients == 0) { + if (dev->priv->clients == NULL) { spice_debug("client removed, memory pool will be freed (%lu bytes)", dev->priv->cur_pool_size); g_list_free_full(dev->priv->write_bufs_pool, (GDestroyNotify) spice_char_device_write_buffer_free); @@ -844,7 +839,7 @@ void spice_char_device_stop(SpiceCharDeviceState *dev) void spice_char_device_reset(SpiceCharDeviceState *dev) { - RingItem *client_item; + GList *client_item; spice_char_device_stop(dev); dev->priv->wait_for_migrate_data = FALSE; @@ -859,10 +854,9 @@ void spice_char_device_reset(SpiceCharDeviceState *dev) spice_char_device_write_buffer_release(dev, release_buf); } - RING_FOREACH(client_item, &dev->priv->clients) { - SpiceCharDeviceClientState *dev_client; + for (client_item = dev->priv->clients; client_item != NULL; client_item = client_item->next) { + SpiceCharDeviceClientState *dev_client = client_item->data; - dev_client = SPICE_CONTAINEROF(client_item, SpiceCharDeviceClientState, link); spice_char_device_client_send_queue_free(dev, dev_client); } dev->priv->sin = NULL; @@ -907,10 +901,8 @@ void spice_char_device_state_migrate_data_marshall(SpiceCharDeviceState *dev, SpiceMarshaller *m2; /* multi-clients are not supported */ - spice_assert(dev->priv->num_clients == 1); - client_state = SPICE_CONTAINEROF(ring_get_tail(&dev->priv->clients), - SpiceCharDeviceClientState, - link); + spice_assert(g_list_length(dev->priv->clients) == 1); + client_state = g_list_last(dev->priv->clients)->data; /* FIXME: if there were more than one client before the marshalling, * it is possible that the send_queue length > 0, and the send data * should be migrated as well */ @@ -962,11 +954,10 @@ int spice_char_device_state_restore(SpiceCharDeviceState *dev, SpiceCharDeviceClientState *client_state; uint32_t client_tokens_window; - spice_assert(dev->priv->num_clients == 1 && dev->priv->wait_for_migrate_data); + spice_assert(g_list_length(dev->priv->clients) == 1 && + dev->priv->wait_for_migrate_data); - client_state = SPICE_CONTAINEROF(ring_get_tail(&dev->priv->clients), - SpiceCharDeviceClientState, - link); + client_state = g_list_last(dev->priv->clients)->data; if (mig_data->version > SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION) { spice_error("dev %p error: migration data version %u is bigger than self %u", dev, mig_data->version, SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION); @@ -1139,11 +1130,10 @@ red_char_device_finalize(GObject *object) spice_char_device_write_buffer_free(self->priv->cur_write_buf); } - while (!ring_is_empty(&self->priv->clients)) { - RingItem *item = ring_get_tail(&self->priv->clients); - SpiceCharDeviceClientState *dev_client; + while (self->priv->clients != NULL) { + GList *item = g_list_last(self->priv->clients); + SpiceCharDeviceClientState *dev_client = item->data; - dev_client = SPICE_CONTAINEROF(item, SpiceCharDeviceClientState, link); spice_char_device_client_free(self, dev_client); } self->priv->running = FALSE; @@ -1231,7 +1221,5 @@ red_char_device_init(RedCharDevice *self) { self->priv = RED_CHAR_DEVICE_PRIVATE(self); - ring_init(&self->priv->clients); - g_signal_connect(self, "notify::sin", G_CALLBACK(red_char_device_on_sin_changed), NULL); } |