[Spice-devel,07/11] server/red_worker: assign timer callbacks to worker_core, using spice_timer_queue

Submitted by Yonit Halperin on April 8, 2012, 3:43 p.m.

Details

Message ID 1333899800-1341-7-git-send-email-yhalperi@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Yonit Halperin April 8, 2012, 3:43 p.m.
display channel: Supplying timeouts interface to red_channel, in order to allow
periodic network monitoring.

Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
---
 server/red_worker.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/red_worker.c b/server/red_worker.c
index 9fa3afd..eec4beb 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

Comments

I'd move this right after the 5th patch, ACK otherwise 

On Sun, Apr 08, 2012 at 06:43:16PM +0300, Yonit Halperin wrote:
> display channel: Supplying timeouts interface to red_channel, in order to allow
> periodic network monitoring.
> 
> Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
> ---
>  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 9fa3afd..eec4beb 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
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel