Blame 0117-libcacard-replace-qemu-thread-primitives-with-glib-o.patch

0410ae
From 95d830ad782262bac47e4cc368e8dff108b789f1 Mon Sep 17 00:00:00 2001
0410ae
From: Michael Tokarev <mjt@tls.msk.ru>
0410ae
Date: Thu, 8 May 2014 12:30:48 +0400
0410ae
Subject: [PATCH] libcacard: replace qemu thread primitives with glib ones
0410ae
0410ae
Replace QemuMutex with GMutex and QemuCond with GCond
0410ae
(with corresponding function changes), to make libcacard
0410ae
independent of qemu internal functions.
0410ae
0410ae
After this step, none of libcacard internals use any
0410ae
qemu-provided symbols.  Maybe it's a good idea to
0410ae
stop including qemu-common.h internally too.
0410ae
0410ae
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
0410ae
Reviewed-by: Alon Levy <alevy@redhat.com>
0410ae
Tested-by: Alon Levy <alevy@redhat.com>
0410ae
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0410ae
(cherry picked from commit fd25c0e6dd1ed2aa932fa7ef814b32457bf270fd)
0410ae
---
0410ae
 libcacard/Makefile  |  8 +-------
0410ae
 libcacard/event.c   | 23 ++++++++++-------------
0410ae
 libcacard/vreader.c | 18 ++++++++----------
0410ae
 3 files changed, 19 insertions(+), 30 deletions(-)
0410ae
0410ae
diff --git a/libcacard/Makefile b/libcacard/Makefile
0410ae
index 6b06448..89a5942 100644
0410ae
--- a/libcacard/Makefile
0410ae
+++ b/libcacard/Makefile
0410ae
@@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard
0410ae
 TOOLS += vscclient$(EXESUF)
0410ae
 
0410ae
 # objects linked into a shared library, built with libtool with -fPIC if required
0410ae
-libcacard-obj-y = $(stub-obj-y) $(libcacard-y)
0410ae
-libcacard-obj-y += util/osdep.o util/cutils.o util/qemu-timer-common.o
0410ae
-libcacard-obj-y += util/error.o util/qemu-error.o
0410ae
-libcacard-obj-$(CONFIG_WIN32) += util/oslib-win32.o util/qemu-thread-win32.o
0410ae
-libcacard-obj-$(CONFIG_POSIX) += util/oslib-posix.o util/qemu-thread-posix.o
0410ae
-libcacard-obj-y += $(filter trace/%, $(util-obj-y))
0410ae
-
0410ae
+libcacard-obj-y = $(libcacard-y)
0410ae
 libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y))
0410ae
 
0410ae
 # libtool will build the .o files, too
0410ae
diff --git a/libcacard/event.c b/libcacard/event.c
0410ae
index a2e6c7d..4c551e4 100644
0410ae
--- a/libcacard/event.c
0410ae
+++ b/libcacard/event.c
0410ae
@@ -6,7 +6,6 @@
0410ae
  */
0410ae
 
0410ae
 #include "qemu-common.h"
0410ae
-#include "qemu/thread.h"
0410ae
 
0410ae
 #include "vcard.h"
0410ae
 #include "vreader.h"
0410ae
@@ -43,13 +42,11 @@ vevent_delete(VEvent *vevent)
0410ae
 
0410ae
 static VEvent *vevent_queue_head;
0410ae
 static VEvent *vevent_queue_tail;
0410ae
-static QemuMutex vevent_queue_lock;
0410ae
-static QemuCond vevent_queue_condition;
0410ae
+static CompatGMutex vevent_queue_lock;
0410ae
+static CompatGCond vevent_queue_condition;
0410ae
 
0410ae
 void vevent_queue_init(void)
0410ae
 {
0410ae
-    qemu_mutex_init(&vevent_queue_lock);
0410ae
-    qemu_cond_init(&vevent_queue_condition);
0410ae
     vevent_queue_head = vevent_queue_tail = NULL;
0410ae
 }
0410ae
 
0410ae
@@ -57,7 +54,7 @@ void
0410ae
 vevent_queue_vevent(VEvent *vevent)
0410ae
 {
0410ae
     vevent->next = NULL;
0410ae
-    qemu_mutex_lock(&vevent_queue_lock);
0410ae
+    g_mutex_lock(&vevent_queue_lock);
0410ae
     if (vevent_queue_head) {
0410ae
         assert(vevent_queue_tail);
0410ae
         vevent_queue_tail->next = vevent;
0410ae
@@ -65,8 +62,8 @@ vevent_queue_vevent(VEvent *vevent)
0410ae
         vevent_queue_head = vevent;
0410ae
     }
0410ae
     vevent_queue_tail = vevent;
0410ae
-    qemu_cond_signal(&vevent_queue_condition);
0410ae
-    qemu_mutex_unlock(&vevent_queue_lock);
0410ae
+    g_cond_signal(&vevent_queue_condition);
0410ae
+    g_mutex_unlock(&vevent_queue_lock);
0410ae
 }
0410ae
 
0410ae
 /* must have lock */
0410ae
@@ -86,11 +83,11 @@ VEvent *vevent_wait_next_vevent(void)
0410ae
 {
0410ae
     VEvent *vevent;
0410ae
 
0410ae
-    qemu_mutex_lock(&vevent_queue_lock);
0410ae
+    g_mutex_lock(&vevent_queue_lock);
0410ae
     while ((vevent = vevent_dequeue_vevent()) == NULL) {
0410ae
-        qemu_cond_wait(&vevent_queue_condition, &vevent_queue_lock);
0410ae
+        g_cond_wait(&vevent_queue_condition, &vevent_queue_lock);
0410ae
     }
0410ae
-    qemu_mutex_unlock(&vevent_queue_lock);
0410ae
+    g_mutex_unlock(&vevent_queue_lock);
0410ae
     return vevent;
0410ae
 }
0410ae
 
0410ae
@@ -98,9 +95,9 @@ VEvent *vevent_get_next_vevent(void)
0410ae
 {
0410ae
     VEvent *vevent;
0410ae
 
0410ae
-    qemu_mutex_lock(&vevent_queue_lock);
0410ae
+    g_mutex_lock(&vevent_queue_lock);
0410ae
     vevent = vevent_dequeue_vevent();
0410ae
-    qemu_mutex_unlock(&vevent_queue_lock);
0410ae
+    g_mutex_unlock(&vevent_queue_lock);
0410ae
     return vevent;
0410ae
 }
0410ae
 
0410ae
diff --git a/libcacard/vreader.c b/libcacard/vreader.c
0410ae
index 215a2f6..75b5b28 100644
0410ae
--- a/libcacard/vreader.c
0410ae
+++ b/libcacard/vreader.c
0410ae
@@ -9,10 +9,8 @@
0410ae
 #undef G_LOG_DOMAIN
0410ae
 #endif
0410ae
 #define G_LOG_DOMAIN "libcacard"
0410ae
-#include <glib.h>
0410ae
 
0410ae
 #include "qemu-common.h"
0410ae
-#include "qemu/thread.h"
0410ae
 
0410ae
 #include "vcard.h"
0410ae
 #include "vcard_emul.h"
0410ae
@@ -28,7 +26,7 @@ struct VReaderStruct {
0410ae
     VCard *card;
0410ae
     char *name;
0410ae
     vreader_id_t id;
0410ae
-    QemuMutex lock;
0410ae
+    CompatGMutex lock;
0410ae
     VReaderEmul  *reader_private;
0410ae
     VReaderEmulFree reader_private_free;
0410ae
 };
0410ae
@@ -97,13 +95,13 @@ apdu_ins_to_string(int ins)
0410ae
 static inline void
0410ae
 vreader_lock(VReader *reader)
0410ae
 {
0410ae
-    qemu_mutex_lock(&reader->lock);
0410ae
+    g_mutex_lock(&reader->lock);
0410ae
 }
0410ae
 
0410ae
 static inline void
0410ae
 vreader_unlock(VReader *reader)
0410ae
 {
0410ae
-    qemu_mutex_unlock(&reader->lock);
0410ae
+    g_mutex_unlock(&reader->lock);
0410ae
 }
0410ae
 
0410ae
 /*
0410ae
@@ -116,7 +114,7 @@ vreader_new(const char *name, VReaderEmul *private,
0410ae
     VReader *reader;
0410ae
 
0410ae
     reader = g_new(VReader, 1);
0410ae
-    qemu_mutex_init(&reader->lock);
0410ae
+    g_mutex_init(&reader->lock);
0410ae
     reader->reference_count = 1;
0410ae
     reader->name = g_strdup(name);
0410ae
     reader->card = NULL;
0410ae
@@ -152,6 +150,7 @@ vreader_free(VReader *reader)
0410ae
         return;
0410ae
     }
0410ae
     vreader_unlock(reader);
0410ae
+    g_mutex_clear(&reader->lock);
0410ae
     if (reader->card) {
0410ae
         vcard_free(reader->card);
0410ae
     }
0410ae
@@ -408,25 +407,24 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry)
0410ae
 }
0410ae
 
0410ae
 static VReaderList *vreader_list;
0410ae
-static QemuMutex vreader_list_mutex;
0410ae
+static CompatGMutex vreader_list_mutex;
0410ae
 
0410ae
 static void
0410ae
 vreader_list_init(void)
0410ae
 {
0410ae
     vreader_list = vreader_list_new();
0410ae
-    qemu_mutex_init(&vreader_list_mutex);
0410ae
 }
0410ae
 
0410ae
 static void
0410ae
 vreader_list_lock(void)
0410ae
 {
0410ae
-    qemu_mutex_lock(&vreader_list_mutex);
0410ae
+    g_mutex_lock(&vreader_list_mutex);
0410ae
 }
0410ae
 
0410ae
 static void
0410ae
 vreader_list_unlock(void)
0410ae
 {
0410ae
-    qemu_mutex_unlock(&vreader_list_mutex);
0410ae
+    g_mutex_unlock(&vreader_list_mutex);
0410ae
 }
0410ae
 
0410ae
 static VReaderList *