[Spice-devel] [PATCH 3/5] worker: use GOnce to surround some global init in dispatcher

Frediano Ziglio fziglio at redhat.com
Fri Oct 16 03:49:38 PDT 2015


From: Marc-André Lureau <marcandre.lureau at gmail.com>

---
 server/red_dispatcher.c     | 10 +++++++---
 server/spice_server_utils.h |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index b11cd42..7ad860c 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -1076,11 +1076,15 @@ void red_dispatcher_init(QXLInstance *qxl)
 
     spice_return_if_fail(qxl->st->dispatcher == NULL);
 
-    quic_init();
-    sw_canvas_init();
+    static gsize initialized = FALSE;
+    if (g_once_init_enter(&initialized)) {
+        quic_init();
+        sw_canvas_init();
 #ifdef USE_OPENGL
-    gl_canvas_init();
+        gl_canvas_init();
 #endif // USE_OPENGL
+        g_once_init_leave(&initialized, TRUE);
+    }
 
     red_dispatcher = spice_new0(RedDispatcher, 1);
     ring_init(&red_dispatcher->async_commands);
diff --git a/server/spice_server_utils.h b/server/spice_server_utils.h
index b3ddc27..c8135db 100644
--- a/server/spice_server_utils.h
+++ b/server/spice_server_utils.h
@@ -2,6 +2,7 @@
 #define H_SPICE_SERVER_UTIL
 
 #include <unistd.h>
+#include <glib.h>
 
 static inline void set_bit(int index, uint32_t *addr)
 {
-- 
2.4.3



More information about the Spice-devel mailing list