[Spice-commits] server/red_dispatcher.c server/red_dispatcher.h server/red_worker.c server/red_worker.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Oct 26 01:52:58 PDT 2015


 server/red_dispatcher.c |   28 ++++++++++++++++++++++------
 server/red_dispatcher.h |    7 +++++++
 server/red_worker.c     |    6 ++----
 server/red_worker.h     |    5 -----
 4 files changed, 31 insertions(+), 15 deletions(-)

New commits:
commit 579d65454c1e8fac872460b897d8ac3a66259c00
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Fri Oct 23 10:28:34 2015 +0100

    worker: access dispatcher pending field using helper functions
    
    Signed-off-by: Marc-André Lureau <marcandre.lureau at gmail.com>
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 83aace4..1ad13b8 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -624,14 +624,24 @@ static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
     red_dispatcher_reset_memslots((RedDispatcher*)qxl_worker);
 }
 
+static bool red_dispatcher_set_pending(RedDispatcher *dispatcher, int pending)
+{
+    // this is not atomic but is not an issue
+    if (test_bit(pending, dispatcher->pending)) {
+        return TRUE;
+    }
+
+    set_bit(pending, &dispatcher->pending);
+    return FALSE;
+}
+
 static void red_dispatcher_wakeup(RedDispatcher *dispatcher)
 {
     RedWorkerMessageWakeup payload;
 
-    if (test_bit(RED_WORKER_PENDING_WAKEUP, dispatcher->pending)) {
+    if (red_dispatcher_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
         return;
-    }
-    set_bit(RED_WORKER_PENDING_WAKEUP, &dispatcher->pending);
+
     dispatcher_send_message(&dispatcher->dispatcher,
                             RED_WORKER_MESSAGE_WAKEUP,
                             &payload);
@@ -646,10 +656,9 @@ static void red_dispatcher_oom(RedDispatcher *dispatcher)
 {
     RedWorkerMessageOom payload;
 
-    if (test_bit(RED_WORKER_PENDING_OOM, dispatcher->pending)) {
+    if (red_dispatcher_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
         return;
-    }
-    set_bit(RED_WORKER_PENDING_OOM, &dispatcher->pending);
+
     dispatcher_send_message(&dispatcher->dispatcher,
                             RED_WORKER_MESSAGE_OOM,
                             &payload);
@@ -1177,3 +1186,10 @@ void red_dispatcher_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
 {
     dispatcher_set_opaque(&red_dispatcher->dispatcher, opaque);
 }
+
+void red_dispatcher_clear_pending(RedDispatcher *red_dispatcher, int pending)
+{
+    spice_return_if_fail(red_dispatcher != NULL);
+
+    clear_bit(pending, &red_dispatcher->pending);
+}
diff --git a/server/red_dispatcher.h b/server/red_dispatcher.h
index 9ee36d7..671c013 100644
--- a/server/red_dispatcher.h
+++ b/server/red_dispatcher.h
@@ -294,4 +294,11 @@ typedef struct RedWorkerMessageMonitorsConfigAsync {
 typedef struct RedWorkerMessageDriverUnload {
 } RedWorkerMessageDriverUnload;
 
+enum {
+    RED_DISPATCHER_PENDING_WAKEUP,
+    RED_DISPATCHER_PENDING_OOM,
+};
+
+void red_dispatcher_clear_pending(RedDispatcher *red_dispatcher, int pending);
+
 #endif
diff --git a/server/red_worker.c b/server/red_worker.c
index 3d326d1..719ffd1 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -610,7 +610,6 @@ typedef struct RedWorker {
 
     int channel;
     int running;
-    uint32_t *pending;
     struct pollfd poll_fds[MAX_EVENT_SOURCES];
     struct SpiceWatch watches[MAX_EVENT_SOURCES];
     unsigned int event_timeout;
@@ -11007,8 +11006,8 @@ void handle_dev_wakeup(void *opaque, void *payload)
 {
     RedWorker *worker = opaque;
 
-    clear_bit(RED_WORKER_PENDING_WAKEUP, worker->pending);
     stat_inc_counter(worker->wakeup_counter, 1);
+    red_dispatcher_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_WAKEUP);
 }
 
 void handle_dev_oom(void *opaque, void *payload)
@@ -11041,7 +11040,7 @@ void handle_dev_oom(void *opaque, void *payload)
                 worker->current_size,
                 worker->display_channel ?
                 red_channel_sum_pipes_size(display_red_channel) : 0);
-    clear_bit(RED_WORKER_PENDING_OOM, worker->pending);
+    red_dispatcher_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_OOM);
 }
 
 void handle_dev_reset_cursor(void *opaque, void *payload)
@@ -11616,7 +11615,6 @@ RedWorker* red_worker_new(WorkerInitData *init_data)
     if (worker->record_fd) {
         dispatcher_register_universal_handler(dispatcher, worker_dispatcher_record);
     }
-    worker->pending = init_data->pending;
     worker->cursor_visible = TRUE;
     spice_assert(init_data->num_renderers > 0);
     worker->num_renderers = init_data->num_renderers;
diff --git a/server/red_worker.h b/server/red_worker.h
index 7732e39..e2443c4 100644
--- a/server/red_worker.h
+++ b/server/red_worker.h
@@ -24,11 +24,6 @@
 #include "red_dispatcher.h"
 
 enum {
-    RED_WORKER_PENDING_WAKEUP,
-    RED_WORKER_PENDING_OOM,
-};
-
-enum {
     RED_RENDERER_INVALID,
     RED_RENDERER_SW,
     RED_RENDERER_OGL_PBUF,


More information about the Spice-commits mailing list