Commit c72564ff authored by Michael Tokarev's avatar Michael Tokarev Committed by Paolo Bonzini

libcacard: replace qemu thread primitives with glib ones

Replace QemuMutex with GMutex and QemuCond with GCond
(with corresponding function changes), to make libcacard
independent of qemu internal functions.

After this step, none of libcacard internals use any
qemu-provided symbols.  Maybe it's a good idea to
stop including qemu-common.h internally too.
Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
Reviewed-by: default avatarAlon Levy <alevy@redhat.com>
Tested-by: default avatarAlon Levy <alevy@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent b10c7c00
...@@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard ...@@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard
TOOLS += vscclient$(EXESUF) TOOLS += vscclient$(EXESUF)
# objects linked into a shared library, built with libtool with -fPIC if required # objects linked into a shared library, built with libtool with -fPIC if required
libcacard-obj-y = $(stub-obj-y) $(libcacard-y) libcacard-obj-y = $(libcacard-y)
libcacard-obj-y += util/osdep.o util/cutils.o util/qemu-timer-common.o
libcacard-obj-y += util/error.o util/qemu-error.o
libcacard-obj-$(CONFIG_WIN32) += util/oslib-win32.o util/qemu-thread-win32.o
libcacard-obj-$(CONFIG_POSIX) += util/oslib-posix.o util/qemu-thread-posix.o
libcacard-obj-y += $(filter trace/%, $(util-obj-y))
libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y)) libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y))
# libtool will build the .o files, too # libtool will build the .o files, too
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
#include "qemu-common.h" #include "qemu-common.h"
#include "qemu/thread.h"
#include "vcard.h" #include "vcard.h"
#include "vreader.h" #include "vreader.h"
...@@ -43,13 +42,11 @@ vevent_delete(VEvent *vevent) ...@@ -43,13 +42,11 @@ vevent_delete(VEvent *vevent)
static VEvent *vevent_queue_head; static VEvent *vevent_queue_head;
static VEvent *vevent_queue_tail; static VEvent *vevent_queue_tail;
static QemuMutex vevent_queue_lock; static CompatGMutex vevent_queue_lock;
static QemuCond vevent_queue_condition; static CompatGCond vevent_queue_condition;
void vevent_queue_init(void) void vevent_queue_init(void)
{ {
qemu_mutex_init(&vevent_queue_lock);
qemu_cond_init(&vevent_queue_condition);
vevent_queue_head = vevent_queue_tail = NULL; vevent_queue_head = vevent_queue_tail = NULL;
} }
...@@ -57,7 +54,7 @@ void ...@@ -57,7 +54,7 @@ void
vevent_queue_vevent(VEvent *vevent) vevent_queue_vevent(VEvent *vevent)
{ {
vevent->next = NULL; vevent->next = NULL;
qemu_mutex_lock(&vevent_queue_lock); g_mutex_lock(&vevent_queue_lock);
if (vevent_queue_head) { if (vevent_queue_head) {
assert(vevent_queue_tail); assert(vevent_queue_tail);
vevent_queue_tail->next = vevent; vevent_queue_tail->next = vevent;
...@@ -65,8 +62,8 @@ vevent_queue_vevent(VEvent *vevent) ...@@ -65,8 +62,8 @@ vevent_queue_vevent(VEvent *vevent)
vevent_queue_head = vevent; vevent_queue_head = vevent;
} }
vevent_queue_tail = vevent; vevent_queue_tail = vevent;
qemu_cond_signal(&vevent_queue_condition); g_cond_signal(&vevent_queue_condition);
qemu_mutex_unlock(&vevent_queue_lock); g_mutex_unlock(&vevent_queue_lock);
} }
/* must have lock */ /* must have lock */
...@@ -86,11 +83,11 @@ VEvent *vevent_wait_next_vevent(void) ...@@ -86,11 +83,11 @@ VEvent *vevent_wait_next_vevent(void)
{ {
VEvent *vevent; VEvent *vevent;
qemu_mutex_lock(&vevent_queue_lock); g_mutex_lock(&vevent_queue_lock);
while ((vevent = vevent_dequeue_vevent()) == NULL) { while ((vevent = vevent_dequeue_vevent()) == NULL) {
qemu_cond_wait(&vevent_queue_condition, &vevent_queue_lock); g_cond_wait(&vevent_queue_condition, &vevent_queue_lock);
} }
qemu_mutex_unlock(&vevent_queue_lock); g_mutex_unlock(&vevent_queue_lock);
return vevent; return vevent;
} }
...@@ -98,9 +95,9 @@ VEvent *vevent_get_next_vevent(void) ...@@ -98,9 +95,9 @@ VEvent *vevent_get_next_vevent(void)
{ {
VEvent *vevent; VEvent *vevent;
qemu_mutex_lock(&vevent_queue_lock); g_mutex_lock(&vevent_queue_lock);
vevent = vevent_dequeue_vevent(); vevent = vevent_dequeue_vevent();
qemu_mutex_unlock(&vevent_queue_lock); g_mutex_unlock(&vevent_queue_lock);
return vevent; return vevent;
} }
...@@ -9,10 +9,8 @@ ...@@ -9,10 +9,8 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#endif #endif
#define G_LOG_DOMAIN "libcacard" #define G_LOG_DOMAIN "libcacard"
#include <glib.h>
#include "qemu-common.h" #include "qemu-common.h"
#include "qemu/thread.h"
#include "vcard.h" #include "vcard.h"
#include "vcard_emul.h" #include "vcard_emul.h"
...@@ -28,7 +26,7 @@ struct VReaderStruct { ...@@ -28,7 +26,7 @@ struct VReaderStruct {
VCard *card; VCard *card;
char *name; char *name;
vreader_id_t id; vreader_id_t id;
QemuMutex lock; CompatGMutex lock;
VReaderEmul *reader_private; VReaderEmul *reader_private;
VReaderEmulFree reader_private_free; VReaderEmulFree reader_private_free;
}; };
...@@ -97,13 +95,13 @@ apdu_ins_to_string(int ins) ...@@ -97,13 +95,13 @@ apdu_ins_to_string(int ins)
static inline void static inline void
vreader_lock(VReader *reader) vreader_lock(VReader *reader)
{ {
qemu_mutex_lock(&reader->lock); g_mutex_lock(&reader->lock);
} }
static inline void static inline void
vreader_unlock(VReader *reader) vreader_unlock(VReader *reader)
{ {
qemu_mutex_unlock(&reader->lock); g_mutex_unlock(&reader->lock);
} }
/* /*
...@@ -116,7 +114,7 @@ vreader_new(const char *name, VReaderEmul *private, ...@@ -116,7 +114,7 @@ vreader_new(const char *name, VReaderEmul *private,
VReader *reader; VReader *reader;
reader = g_new(VReader, 1); reader = g_new(VReader, 1);
qemu_mutex_init(&reader->lock); g_mutex_init(&reader->lock);
reader->reference_count = 1; reader->reference_count = 1;
reader->name = g_strdup(name); reader->name = g_strdup(name);
reader->card = NULL; reader->card = NULL;
...@@ -152,6 +150,7 @@ vreader_free(VReader *reader) ...@@ -152,6 +150,7 @@ vreader_free(VReader *reader)
return; return;
} }
vreader_unlock(reader); vreader_unlock(reader);
g_mutex_clear(&reader->lock);
if (reader->card) { if (reader->card) {
vcard_free(reader->card); vcard_free(reader->card);
} }
...@@ -406,25 +405,24 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry) ...@@ -406,25 +405,24 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry)
} }
static VReaderList *vreader_list; static VReaderList *vreader_list;
static QemuMutex vreader_list_mutex; static CompatGMutex vreader_list_mutex;
static void static void
vreader_list_init(void) vreader_list_init(void)
{ {
vreader_list = vreader_list_new(); vreader_list = vreader_list_new();
qemu_mutex_init(&vreader_list_mutex);
} }
static void static void
vreader_list_lock(void) vreader_list_lock(void)
{ {
qemu_mutex_lock(&vreader_list_mutex); g_mutex_lock(&vreader_list_mutex);
} }
static void static void
vreader_list_unlock(void) vreader_list_unlock(void)
{ {
qemu_mutex_unlock(&vreader_list_mutex); g_mutex_unlock(&vreader_list_mutex);
} }
static VReaderList * static VReaderList *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment