summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2015-10-05 14:22:31 -0500
committerFrediano Ziglio <fziglio@redhat.com>2015-11-11 12:13:40 +0000
commita76a9702f7afabd5e63028b35d496c1d890e06a9 (patch)
treefeb3806498ec41c58f514271c6113a89b79b662b
parentbfc9f1d64d1a47c6b4e52d63e91064b603bb1993 (diff)
c5ea9dabba8d5a37734af282636b3974f7d92764 Change RedCharDevicePrivate::clients to GListdaily-20151111
More Ring cleanup
-rw-r--r--server/char-device.c70
1 files changed, 29 insertions, 41 deletions
diff --git a/server/char-device.c b/server/char-device.c
index 12086d40..717d1aae 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -30,7 +30,6 @@
typedef struct SpiceCharDeviceClientState SpiceCharDeviceClientState;
struct SpiceCharDeviceClientState {
- RingItem link;
SpiceCharDeviceState *dev;
RedClient *client;
int do_flow_control;
@@ -56,8 +55,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;
@@ -210,8 +208,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);
}
@@ -225,12 +222,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;
}
@@ -256,13 +252,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;
@@ -298,12 +292,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));
@@ -313,6 +308,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;
}
}
@@ -341,7 +337,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);
@@ -748,7 +744,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;
@@ -762,8 +758,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;
@@ -783,7 +778,7 @@ 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);
}
@@ -817,7 +812,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;
@@ -832,10 +827,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;
@@ -880,10 +874,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 */
@@ -935,11 +927,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);
@@ -1112,11 +1103,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;
@@ -1204,7 +1194,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);
}