[Spice-devel,spice-server,2/2] RFC: Handle timeout for joining drawables

Submitted by Frediano Ziglio on Dec. 6, 2016, 12:28 p.m.

Details

Message ID 20161206122833.30944-3-fziglio@redhat.com
State New
Headers show
Series "RHEL7 improvements" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Dec. 6, 2016, 12:28 p.m.
The previous patch join correctly the commands however if there
are no more commands the command joined is delayed till new
commands arrive. This patch introduce a timeout (currently 10 ms)
after the command is executed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/red-worker.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/red-worker.c b/server/red-worker.c
index b841782..9feb130 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -85,6 +85,7 @@  struct RedWorker {
     RedRecord *record;
     GMainLoop *loop;
 
+    uint64_t joinable_timeout;
     RedDrawable *joinable_drawable;
 };
 
@@ -330,7 +331,7 @@  static int red_process_display(RedWorker *worker, int *ring_is_empty)
                 continue;
             }
             worker->display_poll_tries++;
-            return n;
+            goto exit;
         }
 
         if (worker->record) {
@@ -368,6 +369,7 @@  static int red_process_display(RedWorker *worker, int *ring_is_empty)
                     red_drawable_unref(worker->joinable_drawable);
                 }
                 // try to join with next one
+                worker->joinable_timeout = spice_get_monotonic_time_ns() + NSEC_PER_SEC / 100;
                 worker->joinable_drawable = red_drawable;
                 break;
             }
@@ -425,10 +427,23 @@  static int red_process_display(RedWorker *worker, int *ring_is_empty)
         if (red_channel_all_blocked(RED_CHANNEL(worker->display_channel))
             || spice_get_monotonic_time_ns() - start > NSEC_PER_SEC / 100) {
             worker->event_timeout = 0;
-            return n;
+            goto exit;
         }
     }
     worker->was_blocked = TRUE;
+
+exit:
+    // check pending joinable
+    if (worker->joinable_drawable) {
+        if (spice_get_monotonic_time_ns() >= worker->joinable_timeout) {
+            display_channel_process_draw(worker->display_channel, worker->joinable_drawable,
+                                         worker->process_display_generation);
+            red_drawable_unref(worker->joinable_drawable);
+            worker->joinable_drawable = NULL;
+        } else {
+            worker->event_timeout = MIN(worker->event_timeout, 10);
+        }
+    }
     return n;
 }