[Spice-devel] [PATCH spice-server 04/16] test-display-base: Protect the wake up timer start with a mutex

Frediano Ziglio fziglio at redhat.com
Mon Sep 4 10:57:12 UTC 2017


Timers in spice server are supposed to be used in a single thread
context. To avoid problems protect the usage from multiple
thread with a mutex.
This sometimes caused a crash.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/tests/test-display-base.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index da33ad08..f77f9659 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -84,6 +84,10 @@ static int control = 3; //used to know when we can take a screenshot
 static int rects = 16; //number of rects that will be draw
 static int has_automated_tests = 0; //automated test flag
 
+// SPICE implementation is not designed to have a timer shared
+// between multiple threads so use a mutex
+static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 __attribute__((noreturn))
 static void sigchld_handler(SPICE_GNUC_UNUSED int signal_num) // wait for the child process and exit
 {
@@ -637,7 +641,9 @@ static int req_cmd_notification(QXLInstance *qin)
 {
     Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
 
+    pthread_mutex_lock(&timer_mutex);
     test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
+    pthread_mutex_unlock(&timer_mutex);
     return TRUE;
 }
 
@@ -651,7 +657,9 @@ static void do_wakeup(void *opaque)
         produce_command(test);
     }
 
+    pthread_mutex_lock(&timer_mutex);
     test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
+    pthread_mutex_unlock(&timer_mutex);
     spice_qxl_wakeup(&test->qxl_instance);
 }
 
-- 
2.13.5



More information about the Spice-devel mailing list