[Spice-devel] [PATCH 11/18] char-device: use local 'reds' variable
Frediano Ziglio
fziglio at redhat.com
Thu Feb 4 15:57:43 UTC 2016
From: Jonathon Jongsma <jjongsma at redhat.com>
Store a reference to the server in the SpiceCharDeviceState struct and
use that rather than the global 'reds' variable
---
server/char-device.c | 34 +++++++++++++++++++---------------
server/char-device.h | 1 +
server/reds.c | 1 +
server/smartcard.c | 1 +
server/spicevmc.c | 1 +
5 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/server/char-device.c b/server/char-device.c
index 6093599..74b1362 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -156,7 +156,7 @@ static void spice_char_device_client_free(SpiceCharDeviceState *dev,
RingItem *item, *next;
if (dev_client->wait_for_tokens_timer) {
- reds_get_core_interface(reds)->timer_remove(dev_client->wait_for_tokens_timer);
+ reds_get_core_interface(dev->reds)->timer_remove(dev_client->wait_for_tokens_timer);
}
spice_char_device_client_send_queue_free(dev, dev_client);
@@ -262,7 +262,7 @@ static void spice_char_device_add_msg_to_client_queue(SpiceCharDeviceClientState
ring_add(&dev_client->send_queue, &msg_item->link);
dev_client->send_queue_size++;
if (!dev_client->wait_for_tokens_started) {
- reds_get_core_interface(reds)->timer_start(dev_client->wait_for_tokens_timer,
+ reds_get_core_interface(dev->reds)->timer_start(dev_client->wait_for_tokens_timer,
SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
dev_client->wait_for_tokens_started = TRUE;
}
@@ -362,6 +362,7 @@ static void spice_char_device_client_send_queue_push(SpiceCharDeviceClientState
static void spice_char_device_send_to_client_tokens_absorb(SpiceCharDeviceClientState *dev_client,
uint32_t tokens)
{
+ SpiceCharDeviceState *dev = dev_client->dev;
dev_client->num_send_tokens += tokens;
if (dev_client->send_queue_size) {
@@ -370,12 +371,12 @@ static void spice_char_device_send_to_client_tokens_absorb(SpiceCharDeviceClient
}
if (spice_char_device_can_send_to_client(dev_client)) {
- reds_get_core_interface(reds)->timer_cancel(dev_client->wait_for_tokens_timer);
+ reds_get_core_interface(dev->reds)->timer_cancel(dev_client->wait_for_tokens_timer);
dev_client->wait_for_tokens_started = FALSE;
spice_char_device_read_from_device(dev_client->dev);
} else if (dev_client->send_queue_size) {
- reds_get_core_interface(reds)->timer_start(dev_client->wait_for_tokens_timer,
- SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
+ reds_get_core_interface(dev->reds)->timer_start(dev_client->wait_for_tokens_timer,
+ SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
dev_client->wait_for_tokens_started = TRUE;
}
}
@@ -456,7 +457,7 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
spice_char_device_state_ref(dev);
if (dev->write_to_dev_timer) {
- reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer);
+ reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
}
sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface, base);
@@ -498,8 +499,8 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
if (dev->running) {
if (dev->cur_write_buf) {
if (dev->write_to_dev_timer) {
- reds_get_core_interface(reds)->timer_start(dev->write_to_dev_timer,
- CHAR_DEVICE_WRITE_TO_TIMEOUT);
+ reds_get_core_interface(dev->reds)->timer_start(dev->write_to_dev_timer,
+ CHAR_DEVICE_WRITE_TO_TIMEOUT);
}
} else {
spice_assert(ring_is_empty(&dev->write_queue));
@@ -516,7 +517,7 @@ static void spice_char_dev_write_retry(void *opaque)
SpiceCharDeviceState *dev = opaque;
if (dev->write_to_dev_timer) {
- reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer);
+ reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
}
spice_char_device_write_to_device(dev);
}
@@ -668,6 +669,7 @@ void spice_char_device_write_buffer_release(SpiceCharDeviceState *dev,
********************************/
SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *sin,
+ RedsState *reds,
uint32_t client_tokens_interval,
uint32_t self_tokens,
SpiceCharDeviceCallbacks *cbs,
@@ -683,6 +685,7 @@ SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *si
char_dev = spice_new0(SpiceCharDeviceState, 1);
char_dev->sin = sin;
+ char_dev->reds = reds;
char_dev->cbs = *cbs;
char_dev->opaque = opaque;
char_dev->client_tokens_interval = client_tokens_interval;
@@ -742,9 +745,9 @@ static void spice_char_device_state_unref(SpiceCharDeviceState *char_dev)
void spice_char_device_state_destroy(SpiceCharDeviceState *char_dev)
{
- reds_on_char_device_state_destroy(reds, char_dev);
+ reds_on_char_device_state_destroy(char_dev->reds, char_dev);
if (char_dev->write_to_dev_timer) {
- reds_get_core_interface(reds)->timer_remove(char_dev->write_to_dev_timer);
+ reds_get_core_interface(char_dev->reds)->timer_remove(char_dev->write_to_dev_timer);
char_dev->write_to_dev_timer = NULL;
}
write_buffers_queue_free(&char_dev->write_queue);
@@ -795,9 +798,10 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev,
dev_client->max_send_queue_size = max_send_queue_size;
dev_client->do_flow_control = do_flow_control;
if (do_flow_control) {
- dev_client->wait_for_tokens_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds),
- device_client_wait_for_tokens_timeout,
- dev_client);
+ dev_client->wait_for_tokens_timer =
+ reds_get_core_interface(dev->reds)->timer_add(reds_get_core_interface(dev->reds),
+ device_client_wait_for_tokens_timeout,
+ dev_client);
if (!dev_client->wait_for_tokens_timer) {
spice_error("failed to create wait for tokens timer");
}
@@ -862,7 +866,7 @@ void spice_char_device_stop(SpiceCharDeviceState *dev)
dev->running = FALSE;
dev->active = FALSE;
if (dev->write_to_dev_timer) {
- reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer);
+ reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
}
}
diff --git a/server/char-device.h b/server/char-device.h
index a9c666a..a6315b0 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -128,6 +128,7 @@ typedef struct SpiceCharDeviceCallbacks {
} SpiceCharDeviceCallbacks;
SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *sin,
+ RedsState *reds,
uint32_t client_tokens_interval,
uint32_t self_tokens,
SpiceCharDeviceCallbacks *cbs,
diff --git a/server/reds.c b/server/reds.c
index 0a39340..b30c4c6 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2949,6 +2949,7 @@ static SpiceCharDeviceState *attach_to_red_agent(RedsState *reds, SpiceCharDevic
char_dev_state_cbs.on_free_self_token = vdi_port_on_free_self_token;
state->base = spice_char_device_state_create(sin,
+ reds,
REDS_TOKENS_TO_SEND,
REDS_NUM_INTERNAL_AGENT_MESSAGES,
&char_dev_state_cbs,
diff --git a/server/smartcard.c b/server/smartcard.c
index 0be3235..0d6ba7b 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -280,6 +280,7 @@ static SmartCardDeviceState *smartcard_device_state_new(SpiceCharDeviceInstance
st = spice_new0(SmartCardDeviceState, 1);
st->chardev_st = spice_char_device_state_create(sin,
+ reds,
0, /* tokens interval */
~0, /* self tokens */
&chardev_cbs,
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 95d840e..4460eab 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -542,6 +542,7 @@ SpiceCharDeviceState *spicevmc_device_connect(SpiceCharDeviceInstance *sin,
char_dev_cbs.remove_client = spicevmc_char_dev_remove_client;
state->chardev_st = spice_char_device_state_create(sin,
+ reds,
0, /* tokens interval */
~0, /* self tokens */
&char_dev_cbs,
--
2.5.0
More information about the Spice-devel
mailing list