summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2015-10-05 14:22:31 -0500
committerFrediano Ziglio <fziglio@redhat.com>2016-02-03 16:42:33 +0000
commit905fad3e2f14c7b3c6923b5936ecb5f38db5040d (patch)
tree8236d83c8b3661658bc0763602ec4aac429b4c6d
parentbd2a43c78f7c7c9f0979b199336730fad85c3385 (diff)
c5ea9dabba8d5a37734af282636b3974f7d92764 Change RedCharDevicePrivate::clients to GListdaily-20160203
More Ring cleanup
-rw-r--r--server/char-device.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/server/char-device.c b/server/char-device.c
index ba5923f8..96182f2a 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -32,7 +32,6 @@
typedef struct SpiceCharDeviceClientState SpiceCharDeviceClientState;
struct SpiceCharDeviceClientState {
- RingItem link;
SpiceCharDeviceState *dev;
RedClient *client;
int do_flow_control;
@@ -59,8 +58,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;
@@ -220,8 +218,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);
}
@@ -235,12 +232,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;
}
@@ -266,13 +262,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;
@@ -308,12 +302,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));
@@ -323,6 +318,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;
}
}
@@ -351,7 +347,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);
@@ -768,7 +764,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;
@@ -782,8 +778,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;
@@ -803,12 +798,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 (%"PRIu64" bytes)", dev->priv->cur_pool_size);
g_list_free_full(dev->priv->write_bufs_pool,
(GDestroyNotify) spice_char_device_write_buffer_free);
@@ -845,7 +840,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;
@@ -860,10 +855,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;
@@ -908,10 +902,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 */
@@ -963,11 +955,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);
@@ -1140,11 +1131,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;
@@ -1232,7 +1222,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);
}