[Spice-devel] [PATCH v2 spice 06/11] server/red_worker: assign timer callbacks to worker_core, using spice_timer_queue

Yonit Halperin yhalperi at redhat.com
Tue Apr 17 03:12:31 PDT 2012


display channel: Supplying timeouts interface to red_channel, in order to allow
periodic network monitoring (see next 2 patches).
---
 server/red_worker.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index c66e397..7c41e08 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -78,6 +78,7 @@
 #include "red_dispatcher.h"
 #include "dispatcher.h"
 #include "main_channel.h"
+#include "spice_timer_queue.h"
 
 //#define COMPRESS_STAT
 //#define DUMP_BITMAP
@@ -9704,6 +9705,11 @@ static void worker_watch_remove(SpiceWatch *watch)
 }
 
 SpiceCoreInterface worker_core = {
+    .timer_add = spice_timer_queue_add,
+    .timer_start = spice_timer_set,
+    .timer_cancel = spice_timer_cancel,
+    .timer_remove = spice_timer_remove,
+
     .watch_update_mask = worker_watch_update_mask,
     .watch_add = worker_watch_add,
     .watch_remove = worker_watch_remove,
@@ -11224,6 +11230,10 @@ static void red_init(RedWorker *worker, WorkerInitData *init_data)
     spice_warn_if(init_data->n_surfaces > NUM_SURFACES);
     worker->n_surfaces = init_data->n_surfaces;
 
+    if (!spice_timer_queue_create()) {
+        spice_error("failed to create timer queue");
+    }
+
     message = RED_WORKER_MESSAGE_READY;
     write_message(worker->channel, &message);
 }
@@ -11257,10 +11267,14 @@ void *red_worker_main(void *arg)
     worker.event_timeout = INF_EVENT_WAIT;
     for (;;) {
         int i, num_events;
+        unsigned int timers_queue_timeout;
 
+        timers_queue_timeout = spice_timer_queue_get_timeout_ms();
         worker.event_timeout = MIN(red_get_streams_timout(&worker), worker.event_timeout);
+        worker.event_timeout = MIN(timers_queue_timeout, worker.event_timeout);
         num_events = poll(worker.poll_fds, MAX_EVENT_SOURCES, worker.event_timeout);
         red_handle_streams_timout(&worker);
+        spice_timer_queue_cb();
 
         if (worker.display_channel) {
             /* during migration, in the dest, the display channel can be initialized
-- 
1.7.7.6



More information about the Spice-devel mailing list