Patchwork [6/7] Teach vnc server to use GThread directly

login
register
mail settings
Submitter Anthony Liguori
Date Jan. 24, 2011, 9 p.m.
Message ID <1295902845-29807-7-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/80242/
State New
Headers show

Comments

Anthony Liguori - Jan. 24, 2011, 9 p.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Stefan Hajnoczi - Jan. 26, 2011, 10:39 a.m.
On Mon, Jan 24, 2011 at 9:00 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> +#ifdef _WIN32
> +GThread *q_thread_create_nosignal(GThreadFunc func,
> +                                  gpointer data,
> +                                  gboolean joinable,
> +                                  GError **error)

Let's not introduce a new naming convention, qemu_* is the norm.

Stefan

Patch

diff --git a/qemu-thread.c b/qemu-thread.c
index 748da5e..6d0c51e 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -14,6 +14,31 @@ 
 #include "qemu-common.h"
 #include "qemu-thread.h"
 
+#ifdef _WIN32
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error)
+{
+    return g_thread_create(func, data, joinable, NULL);
+}
+#else
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error)
+{
+    GThread *tid;
+    sigset_t set, old;
+
+    sigfillset(&set);
+    pthread_sigmask(SIG_SETMASK, &set, &old);
+    tid = g_thread_create(func, data, joinable, error);
+    pthread_sigmask(SIG_SETMASK, &old, NULL);
+    return tid;
+}
+#endif
+
 struct trampoline_data
 {
     QemuThread *thread;
diff --git a/qemu-thread.h b/qemu-thread.h
index 2c99c94..ec7fabd 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -10,6 +10,11 @@  struct QemuThread {
 
 typedef struct QemuThread QemuThread;
 
+GThread *q_thread_create_nosignal(GThreadFunc func,
+                                  gpointer data,
+                                  gboolean joinable,
+                                  GError **error);
+
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index 0c2b1a0..2df245d 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -51,7 +51,7 @@ 
 struct VncJobQueue {
     GCond *cond;
     GStaticMutex mutex;
-    QemuThread thread;
+    GThread *thread;
     Buffer buffer;
     bool exit;
     QTAILQ_HEAD(, VncJob) jobs;
@@ -289,11 +289,11 @@  static void vnc_queue_clear(VncJobQueue *q)
     queue = NULL; /* Unset global queue */
 }
 
-static void *vnc_worker_thread(void *arg)
+static gpointer vnc_worker_thread(gpointer arg)
 {
     VncJobQueue *queue = arg;
 
-    qemu_thread_self(&queue->thread);
+    queue->thread = g_thread_self();
 
     while (!vnc_worker_thread_loop(queue)) ;
     vnc_queue_clear(queue);
@@ -308,7 +308,7 @@  void vnc_start_worker_thread(void)
         return ;
 
     q = vnc_queue_init();
-    qemu_thread_create(&q->thread, vnc_worker_thread, q);
+    q->thread = q_thread_create_nosignal(vnc_worker_thread, q, FALSE, NULL);
     queue = q; /* Set global queue */
 }