* [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups
@ 2014-05-02 14:35 Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
` (6 more replies)
0 siblings, 7 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
Basically libgthread has been rewritten in glib version 2.31, and old ways
to use thread primitives stopped working while new ways appeared. The two
interfaces were sufficiently different to warrant large ifdeffery across all
code using it.
Here's a patchset which tries to clean usage of glib thread interface across
this major rewrite.
The main change was that certain primitives - conditionals and mutexes -
were dynamic-only before 2.31 (ie, should be allocated using foo_new() and
freed using foo_free()), while in 2.31 and up, _new()/_free() has been
deprecated, and new primitives, _init()/_clear(), were added. So before
2.31, we had to declare a pointer call foo_new() to allocate actual object,
and use this pointer when calling all functions which use this object,
while in 2.31+, we have to declare actual object and use its address when
calling functions.
The trick to make this stuff happy for old glib which I used is to re-define
actual type to be a pointer to that type, using #define, like this:
#define GMutex GMutex*
so every time the code refers to GMutex it actually refers to a pointer to
that object. Plus wrapper #define and inline functioins which accept such
a pointer and call actual glib function after dereferencing it, like this:
static inline g_forward_compat_mutex_lock(GMutex **mutex)
{
g_mutex_lock(*mutex);
}
#undef g_mutex_lock
#define g_mutex_lock(mutex) g_forward_compat_mutex_lock(mutex)
This way, we use new, 2.31+, glib interface everywhere, but for pre-2.31
glib, this interface is wrapped using old API and by converting the
actual object to a pointer to actual object behind the scenes.
It is hackish, but this allows to write very very clean, new-style, code,
and compile it with old glib.
The only difference with actual new interface is that in new, 2.31+, glib,
those objects, when declared statically, don't need to be initialized and
will just work when passed to their functions. While for old interface,
actual objects needs to be allocated using g_foo_new(). So I added a
set of functions, g_foo_init_static(), which should be called in the same
place where old code expected to have g_foo_new(). For new interface
those functions evaluates to nothing, but for old interface they call
the allocation routine.
It is not the same as g_foo_init(), -- I wanted to distinguish this
_static() method from regular init() (tho any of those can be used),
because it is easy this way to find places in the code which can
benefit from cleanups later when we'll drop support for glib < 2.31.
Another approach which has been implemented earlier by Stefan Hajnoczi
is to wrap deprecated calls into defines which uses the new API.
To my taste this is more intrusive, since it changes all callers
in non-obvious ways. The approach presented in this series is
more hackish for sure, but is significantly less intrusive to the
callers, allowing using new glib API everywhere.
The whole thing has been compile-tested with both new and old glib
versions on linux and FreeBSD, and runtime-tested on linux (again,
both old and new versions) with --with-coroutine=gthread. I didn't
test libcacard much, because I found no testcases for it, but at
least it _appears_ to work.
The diffstat below does not look like a diffstat of a cleanup, because
the patchset adds about 2 times more lines than it removes. This is
because of large addition to glib-compat.h, plus addition of compat
code to vscclient, to make it independent of qemu.
Changes from first submission:
- replaced pstrcpy() with memcpy() in libcacard as suggested by
Paolo Bonzini, and make this change to be in its own patch
- added a cleanup patch from Stefan Hajnoczi to move g_poll compat
code from qemu-common.h to glib-compat.h
- added call to g_error() to g_thread_new() implementation for old
interface
- adjusted commit messages
Patches 1/7, 2/7 and 5/7 can be used independently as small cleanup
patches, suitable for -trivial tree.
Thanks,
/mjt
Michael Tokarev (6):
do not call g_thread_init() for glib >= 2.31
glib-compat.h: add new thread API emulation on top of pre-2.31 API
vscclient: use glib thread primitives not qemu
libcacard: replace pstrcpy() with memcpy()
libcacard: replace qemu thread primitives with glib ones
libcacard: actually use symbols file
Stefan Hajnoczi (1):
glib: move g_poll() replacement into glib-compat.h
coroutine-gthread.c | 37 +++++---------
include/glib-compat.h | 118 ++++++++++++++++++++++++++++++++++++++++++++
include/qemu-common.h | 12 -----
libcacard/Makefile | 10 +---
libcacard/event.c | 25 +++++-----
libcacard/vcard_emul_nss.c | 3 +-
libcacard/vreader.c | 19 ++++---
libcacard/vscclient.c | 75 ++++++++++++++++------------
trace/simple.c | 50 +++++--------------
util/osdep.c | 21 ++++----
10 files changed, 221 insertions(+), 149 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-trivial] [PATCH v2 1/7] do not call g_thread_init() for glib >= 2.31
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
@ 2014-05-02 14:35 ` Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
` (5 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev
glib >= 2.31 always enables thread support and g_thread_supported()
is #defined to 1, there's no need to call g_thread_init() anymore,
and it definitely does not need to report error which never happens.
Keep code for old < 2.31 glibc anyway for now, just #ifdef it
differently.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-trivial@nongnu.org
---
coroutine-gthread.c | 7 ++-----
util/osdep.c | 21 +++++++++------------
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
index d3e5b99..a61efe0 100644
--- a/coroutine-gthread.c
+++ b/coroutine-gthread.c
@@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
static void __attribute__((constructor)) coroutine_init(void)
{
- if (!g_thread_supported()) {
#if !GLIB_CHECK_VERSION(2, 31, 0)
+ if (!g_thread_supported()) {
g_thread_init(NULL);
-#else
- fprintf(stderr, "glib threading failed to initialize.\n");
- exit(1);
-#endif
}
+#endif
init_coroutine_cond();
}
diff --git a/util/osdep.c b/util/osdep.c
index a9029f8..b2bd154 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -436,23 +436,20 @@ int socket_init(void)
return 0;
}
-/* Ensure that glib is running in multi-threaded mode */
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+/* Ensure that glib is running in multi-threaded mode
+ * Old versions of glib require explicit initialization. Failure to do
+ * this results in the single-threaded code paths being taken inside
+ * glib. For example, the g_slice allocator will not be thread-safe
+ * and cause crashes.
+ */
static void __attribute__((constructor)) thread_init(void)
{
if (!g_thread_supported()) {
-#if !GLIB_CHECK_VERSION(2, 31, 0)
- /* Old versions of glib require explicit initialization. Failure to do
- * this results in the single-threaded code paths being taken inside
- * glib. For example, the g_slice allocator will not be thread-safe
- * and cause crashes.
- */
- g_thread_init(NULL);
-#else
- fprintf(stderr, "glib threading failed to initialize.\n");
- exit(1);
-#endif
+ g_thread_init(NULL);
}
}
+#endif
#ifndef CONFIG_IOVEC
/* helper function for iov_send_recv() */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 1/7] do not call g_thread_init() for glib >= 2.31
@ 2014-05-02 14:35 ` Michael Tokarev
0 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev
glib >= 2.31 always enables thread support and g_thread_supported()
is #defined to 1, there's no need to call g_thread_init() anymore,
and it definitely does not need to report error which never happens.
Keep code for old < 2.31 glibc anyway for now, just #ifdef it
differently.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-trivial@nongnu.org
---
coroutine-gthread.c | 7 ++-----
util/osdep.c | 21 +++++++++------------
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
index d3e5b99..a61efe0 100644
--- a/coroutine-gthread.c
+++ b/coroutine-gthread.c
@@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
static void __attribute__((constructor)) coroutine_init(void)
{
- if (!g_thread_supported()) {
#if !GLIB_CHECK_VERSION(2, 31, 0)
+ if (!g_thread_supported()) {
g_thread_init(NULL);
-#else
- fprintf(stderr, "glib threading failed to initialize.\n");
- exit(1);
-#endif
}
+#endif
init_coroutine_cond();
}
diff --git a/util/osdep.c b/util/osdep.c
index a9029f8..b2bd154 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -436,23 +436,20 @@ int socket_init(void)
return 0;
}
-/* Ensure that glib is running in multi-threaded mode */
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+/* Ensure that glib is running in multi-threaded mode
+ * Old versions of glib require explicit initialization. Failure to do
+ * this results in the single-threaded code paths being taken inside
+ * glib. For example, the g_slice allocator will not be thread-safe
+ * and cause crashes.
+ */
static void __attribute__((constructor)) thread_init(void)
{
if (!g_thread_supported()) {
-#if !GLIB_CHECK_VERSION(2, 31, 0)
- /* Old versions of glib require explicit initialization. Failure to do
- * this results in the single-threaded code paths being taken inside
- * glib. For example, the g_slice allocator will not be thread-safe
- * and cause crashes.
- */
- g_thread_init(NULL);
-#else
- fprintf(stderr, "glib threading failed to initialize.\n");
- exit(1);
-#endif
+ g_thread_init(NULL);
}
}
+#endif
#ifndef CONFIG_IOVEC
/* helper function for iov_send_recv() */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-trivial] [PATCH v2 2/7] glib: move g_poll() replacement into glib-compat.h
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
@ 2014-05-02 14:35 ` Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
` (5 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev, Stefan Hajnoczi
From: Stefan Hajnoczi <stefanha@redhat.com>
We have a dedicated header file for wrappers to smooth over glib version
differences. Move the g_poll() definition into glib-compat.h for
consistency.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org
---
include/glib-compat.h | 12 ++++++++++++
include/qemu-common.h | 12 ------------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 8aa77af..8d25900 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -24,4 +24,16 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
}
#endif
+#if !GLIB_CHECK_VERSION(2, 20, 0)
+/*
+ * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
+ * on older systems.
+ */
+static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
+{
+ GMainContext *ctx = g_main_context_default();
+ return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
+}
+#endif
+
#endif
diff --git a/include/qemu-common.h b/include/qemu-common.h
index a998e8d..3f3fd60 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -124,18 +124,6 @@ int qemu_main(int argc, char **argv, char **envp);
void qemu_get_timedate(struct tm *tm, int offset);
int qemu_timedate_diff(struct tm *tm);
-#if !GLIB_CHECK_VERSION(2, 20, 0)
-/*
- * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
- * on older systems.
- */
-static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
-{
- GMainContext *ctx = g_main_context_default();
- return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
-}
-#endif
-
/**
* is_help_option:
* @s: string to test
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 2/7] glib: move g_poll() replacement into glib-compat.h
@ 2014-05-02 14:35 ` Michael Tokarev
0 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev, Stefan Hajnoczi
From: Stefan Hajnoczi <stefanha@redhat.com>
We have a dedicated header file for wrappers to smooth over glib version
differences. Move the g_poll() definition into glib-compat.h for
consistency.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org
---
include/glib-compat.h | 12 ++++++++++++
include/qemu-common.h | 12 ------------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 8aa77af..8d25900 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -24,4 +24,16 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
}
#endif
+#if !GLIB_CHECK_VERSION(2, 20, 0)
+/*
+ * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
+ * on older systems.
+ */
+static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
+{
+ GMainContext *ctx = g_main_context_default();
+ return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
+}
+#endif
+
#endif
diff --git a/include/qemu-common.h b/include/qemu-common.h
index a998e8d..3f3fd60 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -124,18 +124,6 @@ int qemu_main(int argc, char **argv, char **envp);
void qemu_get_timedate(struct tm *tm, int offset);
int qemu_timedate_diff(struct tm *tm);
-#if !GLIB_CHECK_VERSION(2, 20, 0)
-/*
- * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
- * on older systems.
- */
-static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
-{
- GMainContext *ctx = g_main_context_default();
- return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
-}
-#endif
-
/**
* is_help_option:
* @s: string to test
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 3/7] glib-compat.h: add new thread API emulation on top of pre-2.31 API
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
@ 2014-05-02 14:35 ` Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] [PATCH v2 4/7] vscclient: use glib thread primitives not qemu Michael Tokarev
` (3 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
Thread API changed in glib-2.31 significantly. Before that version,
conditionals and mutexes were only allocated dynamically, using
_new()/_free() interface. in 2.31 and up, they're allocated statically
as regular variables, and old interface is deprecated.
(Note: glib docs says the new interface is available since version
2.32, but it was actually introduced in version 2.31).
Create the new interface using old primitives, re-defining the base
types (GCond and GMutex) to be pointers.
Replace #ifdeffery around GCond and GMutex in trace/simple.c and
coroutine-gthread.c too because it does not work anymore with the new
glib-compat.h.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
coroutine-gthread.c | 30 +++++---------
include/glib-compat.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++
trace/simple.c | 50 ++++++-----------------
3 files changed, 129 insertions(+), 57 deletions(-)
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
index a61efe0..a4813d9 100644
--- a/coroutine-gthread.c
+++ b/coroutine-gthread.c
@@ -30,20 +30,14 @@ typedef struct {
CoroutineAction action;
} CoroutineGThread;
-static GStaticMutex coroutine_lock = G_STATIC_MUTEX_INIT;
+static GMutex coroutine_lock;
+static GCond coroutine_cond;
/* GLib 2.31 and beyond deprecated various parts of the thread API,
* but the new interfaces are not available in older GLib versions
* so we have to cope with both.
*/
#if GLIB_CHECK_VERSION(2, 31, 0)
-/* Default zero-initialisation is sufficient for 2.31+ GCond */
-static GCond the_coroutine_cond;
-static GCond *coroutine_cond = &the_coroutine_cond;
-static inline void init_coroutine_cond(void)
-{
-}
-
/* Awkwardly, the GPrivate API doesn't provide a way to update the
* GDestroyNotify handler for the coroutine key dynamically. So instead
* we track whether or not the CoroutineGThread should be freed on
@@ -84,11 +78,6 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
#else
/* Handle older GLib versions */
-static GCond *coroutine_cond;
-static inline void init_coroutine_cond(void)
-{
- coroutine_cond = g_cond_new();
-}
static GStaticPrivate coroutine_key = G_STATIC_PRIVATE_INIT;
@@ -121,21 +110,22 @@ static void __attribute__((constructor)) coroutine_init(void)
}
#endif
- init_coroutine_cond();
+ g_cond_init_static(&coroutine_cond);
+ g_mutex_init_static(&coroutine_lock);
}
static void coroutine_wait_runnable_locked(CoroutineGThread *co)
{
while (!co->runnable) {
- g_cond_wait(coroutine_cond, g_static_mutex_get_mutex(&coroutine_lock));
+ g_cond_wait(&coroutine_cond, &coroutine_lock);
}
}
static void coroutine_wait_runnable(CoroutineGThread *co)
{
- g_static_mutex_lock(&coroutine_lock);
+ g_mutex_lock(&coroutine_lock);
coroutine_wait_runnable_locked(co);
- g_static_mutex_unlock(&coroutine_lock);
+ g_mutex_unlock(&coroutine_lock);
}
static gpointer coroutine_thread(gpointer opaque)
@@ -177,17 +167,17 @@ CoroutineAction qemu_coroutine_switch(Coroutine *from_,
CoroutineGThread *from = DO_UPCAST(CoroutineGThread, base, from_);
CoroutineGThread *to = DO_UPCAST(CoroutineGThread, base, to_);
- g_static_mutex_lock(&coroutine_lock);
+ g_mutex_lock(&coroutine_lock);
from->runnable = false;
from->action = action;
to->runnable = true;
to->action = action;
- g_cond_broadcast(coroutine_cond);
+ g_cond_broadcast(&coroutine_cond);
if (action != COROUTINE_TERMINATE) {
coroutine_wait_runnable_locked(from);
}
- g_static_mutex_unlock(&coroutine_lock);
+ g_mutex_unlock(&coroutine_lock);
return from->action;
}
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 8d25900..34a7967 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -5,6 +5,7 @@
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
+ * Michael Tokarev <mjt@tls.msk.ru>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
@@ -36,4 +37,109 @@ static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
}
#endif
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+/* before glib-2.31, GMutex and GCond was dynamic-only.
+ * We redefine GMutex to GMutex* and create new _init()/_clear()
+ * primitives using old _new()/_free() primitives.
+ * The tricky part is to re-define the types.
+ * g_forward_compat_ prefix is used for inline functions.
+ * This is done as both inline function and a macro because original
+ * glib symbols which we redefine were actually macros.
+ */
+
+#define GMutex GMutex *
+#define GCond GCond *
+
+static inline void g_mutex_init(GMutex *mutex)
+{
+ *mutex = g_mutex_new();
+}
+
+static inline void g_mutex_clear(GMutex *mutex)
+{
+ g_mutex_free(*mutex);
+ *mutex = NULL;
+}
+
+#define g_mutex_init_static(mutex) g_mutex_init(mutex)
+#define g_mutex_clear_static(mutex) g_mutex_clear(mutex)
+
+static inline void g_forward_compat_mutex_lock(GMutex *mutex)
+{
+ g_mutex_lock(*mutex);
+}
+#undef g_mutex_lock
+#define g_mutex_lock(mutex) g_forward_compat_mutex_lock(mutex)
+
+static inline gboolean g_forward_compat_mutex_trylock(GMutex *mutex)
+{
+ return g_mutex_trylock(*mutex);
+}
+#undef g_mutex_trylock
+#define g_mutex_trylock(mutex) g_forward_compat_mutex_trylock(mutex)
+
+static inline void g_forward_compat_mutex_unlock(GMutex *mutex)
+{
+ g_mutex_unlock(*mutex);
+}
+#undef g_mutex_unlock
+#define g_mutex_unlock(mutex) g_forward_compat_mutex_unlock(mutex)
+
+
+static inline void g_cond_init(GCond *cond)
+{
+ *cond = g_cond_new();
+}
+
+static inline void g_cond_clear(GCond *cond)
+{
+ g_cond_free(*cond);
+ *cond = NULL;
+}
+
+#define g_cond_init_static(cond) g_cond_init(cond)
+#define g_cond_clear_static(cond) g_cond_clear(cond)
+
+static inline void g_forward_compat_cond_wait(GCond *cond, GMutex *mutex)
+{
+ g_cond_wait(*cond, *mutex);
+}
+#undef g_cond_wait
+#define g_cond_wait(cond, mutex) g_forward_compat_cond_wait(cond, mutex)
+
+static inline void g_forward_compat_cond_broadcast(GCond *cond)
+{
+ g_cond_broadcast(*cond);
+}
+#undef g_cond_broadcast
+#define g_cond_broadcast(cond) g_forward_compat_cond_broadcast(cond)
+
+static inline void g_forward_compat_cond_signal(GCond *cond)
+{
+ g_cond_signal(*cond);
+}
+#undef g_cond_signal
+#define g_cond_signal(cond) g_forward_compat_cond_signal(cond)
+
+
+/* before 2.31 there was no g_thread_new() */
+static inline GThread *g_thread_new(const char *name,
+ GThreadFunc func, gpointer data)
+{
+ GThread *thread = g_thread_create(func, data, TRUE, NULL);
+ if (!thread) {
+ g_error ("creating thread");
+ }
+ return thread;
+}
+
+#else /* glib 2.31 */
+
+#define g_cond_init_static(cond) do{}while(0)
+#define g_cond_clear_static(cond) do{}while(0)
+#define g_mutex_init_static(cond) do{}while(0)
+#define g_mutex_clear_static(cond) do{}while(0)
+
+#endif /* glib 2.31 */
+
#endif
diff --git a/trace/simple.c b/trace/simple.c
index aaa010e..ae7edeb 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -40,28 +40,9 @@
* Trace records are written out by a dedicated thread. The thread waits for
* records to become available, writes them out, and then waits again.
*/
-#if GLIB_CHECK_VERSION(2, 32, 0)
static GMutex trace_lock;
-#define lock_trace_lock() g_mutex_lock(&trace_lock)
-#define unlock_trace_lock() g_mutex_unlock(&trace_lock)
-#define get_trace_lock_mutex() (&trace_lock)
-#else
-static GStaticMutex trace_lock = G_STATIC_MUTEX_INIT;
-#define lock_trace_lock() g_static_mutex_lock(&trace_lock)
-#define unlock_trace_lock() g_static_mutex_unlock(&trace_lock)
-#define get_trace_lock_mutex() g_static_mutex_get_mutex(&trace_lock)
-#endif
-
-/* g_cond_new() was deprecated in glib 2.31 but we still need to support it */
-#if GLIB_CHECK_VERSION(2, 31, 0)
-static GCond the_trace_available_cond;
-static GCond the_trace_empty_cond;
-static GCond *trace_available_cond = &the_trace_available_cond;
-static GCond *trace_empty_cond = &the_trace_empty_cond;
-#else
-static GCond *trace_available_cond;
-static GCond *trace_empty_cond;
-#endif
+static GCond trace_available_cond;
+static GCond trace_empty_cond;
static bool trace_available;
static bool trace_writeout_enabled;
@@ -150,26 +131,26 @@ static bool get_trace_record(unsigned int idx, TraceRecord **recordptr)
*/
static void flush_trace_file(bool wait)
{
- lock_trace_lock();
+ g_mutex_lock(&trace_lock);
trace_available = true;
- g_cond_signal(trace_available_cond);
+ g_cond_signal(&trace_available_cond);
if (wait) {
- g_cond_wait(trace_empty_cond, get_trace_lock_mutex());
+ g_cond_wait(&trace_empty_cond, &trace_lock);
}
- unlock_trace_lock();
+ g_mutex_unlock(&trace_lock);
}
static void wait_for_trace_records_available(void)
{
- lock_trace_lock();
+ g_mutex_lock(&trace_lock);
while (!(trace_available && trace_writeout_enabled)) {
- g_cond_signal(trace_empty_cond);
- g_cond_wait(trace_available_cond, get_trace_lock_mutex());
+ g_cond_signal(&trace_empty_cond);
+ g_cond_wait(&trace_available_cond, &trace_lock);
}
trace_available = false;
- unlock_trace_lock();
+ g_mutex_unlock(&trace_lock);
}
static gpointer writeout_thread(gpointer opaque)
@@ -397,11 +378,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
pthread_sigmask(SIG_SETMASK, &set, &oldset);
#endif
-#if GLIB_CHECK_VERSION(2, 31, 0)
thread = g_thread_new("trace-thread", fn, NULL);
-#else
- thread = g_thread_create(fn, NULL, FALSE, NULL);
-#endif
#ifndef _WIN32
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
@@ -414,10 +391,9 @@ bool trace_backend_init(const char *events, const char *file)
{
GThread *thread;
-#if !GLIB_CHECK_VERSION(2, 31, 0)
- trace_available_cond = g_cond_new();
- trace_empty_cond = g_cond_new();
-#endif
+ g_cond_init_static(&trace_available_cond);
+ g_cond_init_static(&trace_empty_cond);
+ g_mutex_init_static(&trace_lock);
thread = trace_thread_create(writeout_thread);
if (!thread) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 4/7] vscclient: use glib thread primitives not qemu
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
` (2 preceding siblings ...)
2014-05-02 14:35 ` [Qemu-devel] [PATCH v2 3/7] glib-compat.h: add new thread API emulation on top of pre-2.31 API Michael Tokarev
@ 2014-05-02 14:35 ` Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
` (2 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
Use glib-provided thread primitives in vscclient instead of
qemu ones, and do not use qemu sockets in there (open-code
call to WSAStartup() for windows to initialize things).
This way, vscclient becomes more stand-alone, independent on
qemu internals.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
libcacard/vscclient.c | 75 +++++++++++++++++++++++++++++--------------------
1 file changed, 44 insertions(+), 31 deletions(-)
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 3477ab3..5f87d1c 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -12,12 +12,10 @@
#ifndef _WIN32
#include <netdb.h>
+#define closesocket(x) close(x)
#endif
-#include <glib.h>
#include "qemu-common.h"
-#include "qemu/thread.h"
-#include "qemu/sockets.h"
#include "vscard_common.h"
@@ -54,7 +52,7 @@ print_usage(void) {
static GIOChannel *channel_socket;
static GByteArray *socket_to_send;
-static QemuMutex socket_to_send_lock;
+static GMutex socket_to_send_lock;
static guint socket_tag;
static void
@@ -103,7 +101,7 @@ send_msg(
) {
VSCMsgHeader mhHeader;
- qemu_mutex_lock(&socket_to_send_lock);
+ g_mutex_lock(&socket_to_send_lock);
if (verbose > 10) {
printf("sending type=%d id=%u, len =%u (0x%x)\n",
@@ -117,18 +115,18 @@ send_msg(
g_byte_array_append(socket_to_send, (guint8 *)msg, length);
g_idle_add(socket_prepare_sending, NULL);
- qemu_mutex_unlock(&socket_to_send_lock);
+ g_mutex_unlock(&socket_to_send_lock);
return 0;
}
static VReader *pending_reader;
-static QemuMutex pending_reader_lock;
-static QemuCond pending_reader_condition;
+static GMutex pending_reader_lock;
+static GCond pending_reader_condition;
#define MAX_ATR_LEN 40
-static void *
-event_thread(void *arg)
+static gpointer
+event_thread(gpointer arg)
{
unsigned char atr[MAX_ATR_LEN];
int atr_len = MAX_ATR_LEN;
@@ -149,20 +147,20 @@ event_thread(void *arg)
/* ignore events from readers qemu has rejected */
/* if qemu is still deciding on this reader, wait to see if need to
* forward this event */
- qemu_mutex_lock(&pending_reader_lock);
+ g_mutex_lock(&pending_reader_lock);
if (!pending_reader || (pending_reader != event->reader)) {
/* wasn't for a pending reader, this reader has already been
* rejected by qemu */
- qemu_mutex_unlock(&pending_reader_lock);
+ g_mutex_unlock(&pending_reader_lock);
vevent_delete(event);
continue;
}
/* this reader hasn't been told its status from qemu yet, wait for
* that status */
while (pending_reader != NULL) {
- qemu_cond_wait(&pending_reader_condition, &pending_reader_lock);
+ g_cond_wait(&pending_reader_condition, &pending_reader_lock);
}
- qemu_mutex_unlock(&pending_reader_lock);
+ g_mutex_unlock(&pending_reader_lock);
/* now recheck the id */
reader_id = vreader_get_id(event->reader);
if (reader_id == VSCARD_UNDEFINED_READER_ID) {
@@ -178,12 +176,12 @@ event_thread(void *arg)
/* wait until qemu has responded to our first reader insert
* before we send a second. That way we won't confuse the responses
* */
- qemu_mutex_lock(&pending_reader_lock);
+ g_mutex_lock(&pending_reader_lock);
while (pending_reader != NULL) {
- qemu_cond_wait(&pending_reader_condition, &pending_reader_lock);
+ g_cond_wait(&pending_reader_condition, &pending_reader_lock);
}
pending_reader = vreader_reference(event->reader);
- qemu_mutex_unlock(&pending_reader_lock);
+ g_mutex_unlock(&pending_reader_lock);
reader_name = vreader_get_name(event->reader);
if (verbose > 10) {
printf(" READER INSERT: %s\n", reader_name);
@@ -246,7 +244,6 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
int num_capabilities =
1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t));
int i;
- QemuThread thread_id;
incoming->version = ntohl(incoming->version);
if (incoming->version != VSCARD_VERSION) {
@@ -269,7 +266,7 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0);
/* launch the event_thread. This will trigger reader adds for all the
* existing readers */
- qemu_thread_create(&thread_id, "vsc/event", event_thread, NULL, 0);
+ g_thread_new("vsc/event", event_thread, NULL);
return 0;
}
@@ -379,26 +376,26 @@ do_socket_read(GIOChannel *source,
case VSC_Error:
error_msg = (VSCMsgError *) pbSendBuffer;
if (error_msg->code == VSC_SUCCESS) {
- qemu_mutex_lock(&pending_reader_lock);
+ g_mutex_lock(&pending_reader_lock);
if (pending_reader) {
vreader_set_id(pending_reader, mhHeader.reader_id);
vreader_free(pending_reader);
pending_reader = NULL;
- qemu_cond_signal(&pending_reader_condition);
+ g_cond_signal(&pending_reader_condition);
}
- qemu_mutex_unlock(&pending_reader_lock);
+ g_mutex_unlock(&pending_reader_lock);
break;
}
printf("warning: qemu refused to add reader\n");
if (error_msg->code == VSC_CANNOT_ADD_MORE_READERS) {
/* clear pending reader, qemu can't handle any more */
- qemu_mutex_lock(&pending_reader_lock);
+ g_mutex_lock(&pending_reader_lock);
if (pending_reader) {
pending_reader = NULL;
/* make sure the event loop doesn't hang */
- qemu_cond_signal(&pending_reader_condition);
+ g_cond_signal(&pending_reader_condition);
}
- qemu_mutex_unlock(&pending_reader_lock);
+ g_mutex_unlock(&pending_reader_lock);
}
break;
case VSC_Init:
@@ -602,7 +599,7 @@ connect_to_qemu(
struct addrinfo *server;
int ret, sock;
- sock = qemu_socket(AF_INET, SOCK_STREAM, 0);
+ sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
/* Error */
fprintf(stderr, "Error opening socket!\n");
@@ -655,8 +652,20 @@ main(
int cert_count = 0;
int c, sock;
- if (socket_init() != 0)
+#ifdef _WIN32
+ WSADATA Data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &Data) != 0) {
+ c = WSAGetLastError();
+ fprintf(stderr, "WSAStartup: %d\n", c);
return 1;
+ }
+#endif
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+ if (!g_thread_supported()) {
+ g_thread_init(NULL);
+ }
+#endif
while ((c = getopt(argc, argv, "c:e:pd:")) != -1) {
switch (c) {
@@ -723,13 +732,13 @@ main(
}
socket_to_send = g_byte_array_new();
- qemu_mutex_init(&socket_to_send_lock);
- qemu_mutex_init(&pending_reader_lock);
- qemu_cond_init(&pending_reader_condition);
+ g_mutex_init_static(&socket_to_send_lock);
+ g_mutex_init_static(&pending_reader_lock);
+ g_cond_init_static(&pending_reader_condition);
vcard_emul_init(command_line_options);
- loop = g_main_loop_new(NULL, true);
+ loop = g_main_loop_new(NULL, TRUE);
printf("> ");
fflush(stdout);
@@ -764,6 +773,10 @@ main(
g_io_channel_unref(channel_socket);
g_byte_array_free(socket_to_send, TRUE);
+ g_mutex_clear_static(&socket_to_send_lock);
+ g_mutex_clear_static(&pending_reader_lock);
+ g_cond_clear_static(&pending_reader_condition);
+
closesocket(sock);
return 0;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-trivial] [PATCH v2 5/7] libcacard: replace pstrcpy() with memcpy()
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
@ 2014-05-02 14:35 ` Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
` (5 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev
Commit 2e679780ae86c6ca8 replaced strncpy() with pstrcpy()
in one place in libcacard. This is a qemu-specific function,
while libcacard is a stand-alone library (or tries to be).
But since we know the exact length of the string to copy,
and know that it definitely will fit in the destination
buffer, use memcpy() instead, and null-terminate the string
after that.
An alternative is to use g_strlcpy() or strncpy(), but memcpy()
is more than adequate in this place.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org
---
libcacard/vcard_emul_nss.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index ee2dfae..e2b196d 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1162,7 +1162,8 @@ vcard_emul_options(const char *args)
NEXT_TOKEN(vname)
NEXT_TOKEN(type_params)
type_params_length = MIN(type_params_length, sizeof(type_str)-1);
- pstrcpy(type_str, type_params_length, type_params);
+ memcpy(type_str, type_params, type_params_length);
+ type_str[type_params_length] = '\0';
type = vcard_emul_type_from_string(type_str);
NEXT_TOKEN(type_params)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 5/7] libcacard: replace pstrcpy() with memcpy()
@ 2014-05-02 14:35 ` Michael Tokarev
0 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:35 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev
Commit 2e679780ae86c6ca8 replaced strncpy() with pstrcpy()
in one place in libcacard. This is a qemu-specific function,
while libcacard is a stand-alone library (or tries to be).
But since we know the exact length of the string to copy,
and know that it definitely will fit in the destination
buffer, use memcpy() instead, and null-terminate the string
after that.
An alternative is to use g_strlcpy() or strncpy(), but memcpy()
is more than adequate in this place.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial@nongnu.org
---
libcacard/vcard_emul_nss.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index ee2dfae..e2b196d 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1162,7 +1162,8 @@ vcard_emul_options(const char *args)
NEXT_TOKEN(vname)
NEXT_TOKEN(type_params)
type_params_length = MIN(type_params_length, sizeof(type_str)-1);
- pstrcpy(type_str, type_params_length, type_params);
+ memcpy(type_str, type_params, type_params_length);
+ type_str[type_params_length] = '\0';
type = vcard_emul_type_from_string(type_str);
NEXT_TOKEN(type_params)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 6/7] libcacard: replace qemu thread primitives with glib ones
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
` (4 preceding siblings ...)
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
@ 2014-05-02 14:36 ` Michael Tokarev
2014-05-02 14:36 ` [Qemu-devel] [PATCH v2 7/7] libcacard: actually use symbols file Michael Tokarev
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
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: Michael Tokarev <mjt@tls.msk.ru>
---
libcacard/Makefile | 8 +-------
libcacard/event.c | 25 ++++++++++++-------------
libcacard/vreader.c | 19 +++++++++----------
3 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/libcacard/Makefile b/libcacard/Makefile
index 6b06448..89a5942 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard
TOOLS += vscclient$(EXESUF)
# objects linked into a shared library, built with libtool with -fPIC if required
-libcacard-obj-y = $(stub-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-obj-y = $(libcacard-y)
libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y))
# libtool will build the .o files, too
diff --git a/libcacard/event.c b/libcacard/event.c
index 2d7500f..be11596 100644
--- a/libcacard/event.c
+++ b/libcacard/event.c
@@ -6,7 +6,6 @@
*/
#include "qemu-common.h"
-#include "qemu/thread.h"
#include "vcard.h"
#include "vreader.h"
@@ -43,13 +42,13 @@ vevent_delete(VEvent *vevent)
static VEvent *vevent_queue_head;
static VEvent *vevent_queue_tail;
-static QemuMutex vevent_queue_lock;
-static QemuCond vevent_queue_condition;
+static GMutex vevent_queue_lock;
+static GCond vevent_queue_condition;
void vevent_queue_init(void)
{
- qemu_mutex_init(&vevent_queue_lock);
- qemu_cond_init(&vevent_queue_condition);
+ g_mutex_init_static(&vevent_queue_lock);
+ g_cond_init_static(&vevent_queue_condition);
vevent_queue_head = vevent_queue_tail = NULL;
}
@@ -57,7 +56,7 @@ void
vevent_queue_vevent(VEvent *vevent)
{
vevent->next = NULL;
- qemu_mutex_lock(&vevent_queue_lock);
+ g_mutex_lock(&vevent_queue_lock);
if (vevent_queue_head) {
assert(vevent_queue_tail);
vevent_queue_tail->next = vevent;
@@ -65,8 +64,8 @@ vevent_queue_vevent(VEvent *vevent)
vevent_queue_head = vevent;
}
vevent_queue_tail = vevent;
- qemu_cond_signal(&vevent_queue_condition);
- qemu_mutex_unlock(&vevent_queue_lock);
+ g_cond_signal(&vevent_queue_condition);
+ g_mutex_unlock(&vevent_queue_lock);
}
/* must have lock */
@@ -86,11 +85,11 @@ VEvent *vevent_wait_next_vevent(void)
{
VEvent *vevent;
- qemu_mutex_lock(&vevent_queue_lock);
+ g_mutex_lock(&vevent_queue_lock);
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;
}
@@ -98,9 +97,9 @@ VEvent *vevent_get_next_vevent(void)
{
VEvent *vevent;
- qemu_mutex_lock(&vevent_queue_lock);
+ g_mutex_lock(&vevent_queue_lock);
vevent = vevent_dequeue_vevent();
- qemu_mutex_unlock(&vevent_queue_lock);
+ g_mutex_unlock(&vevent_queue_lock);
return vevent;
}
diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index 5793d73..91799b4 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -9,10 +9,8 @@
#undef G_LOG_DOMAIN
#endif
#define G_LOG_DOMAIN "libcacard"
-#include <glib.h>
#include "qemu-common.h"
-#include "qemu/thread.h"
#include "vcard.h"
#include "vcard_emul.h"
@@ -28,7 +26,7 @@ struct VReaderStruct {
VCard *card;
char *name;
vreader_id_t id;
- QemuMutex lock;
+ GMutex lock;
VReaderEmul *reader_private;
VReaderEmulFree reader_private_free;
};
@@ -97,13 +95,13 @@ apdu_ins_to_string(int ins)
static inline void
vreader_lock(VReader *reader)
{
- qemu_mutex_lock(&reader->lock);
+ g_mutex_lock(&reader->lock);
}
static inline void
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,
VReader *reader;
reader = (VReader *)g_malloc(sizeof(VReader));
- qemu_mutex_init(&reader->lock);
+ g_mutex_init(&reader->lock);
reader->reference_count = 1;
reader->name = g_strdup(name);
reader->card = NULL;
@@ -152,6 +150,7 @@ vreader_free(VReader *reader)
return;
}
vreader_unlock(reader);
+ g_mutex_clear(&reader->lock);
if (reader->card) {
vcard_free(reader->card);
}
@@ -413,25 +412,25 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry)
}
static VReaderList *vreader_list;
-static QemuMutex vreader_list_mutex;
+static GMutex vreader_list_mutex;
static void
vreader_list_init(void)
{
vreader_list = vreader_list_new();
- qemu_mutex_init(&vreader_list_mutex);
+ g_mutex_init_static(&vreader_list_mutex);
}
static void
vreader_list_lock(void)
{
- qemu_mutex_lock(&vreader_list_mutex);
+ g_mutex_lock(&vreader_list_mutex);
}
static void
vreader_list_unlock(void)
{
- qemu_mutex_unlock(&vreader_list_mutex);
+ g_mutex_unlock(&vreader_list_mutex);
}
static VReaderList *
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH v2 7/7] libcacard: actually use symbols file
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
` (5 preceding siblings ...)
2014-05-02 14:36 ` [Qemu-devel] [PATCH v2 6/7] libcacard: replace qemu thread primitives with glib ones Michael Tokarev
@ 2014-05-02 14:36 ` Michael Tokarev
6 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-02 14:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
libtool has an argument for .syms file, which is -export-symbols.
There's no argument `-export-syms', and it looks like at least on
linux, -export-syms is just ignored. Use the correct argument,
-export-symbols, to actually get the right export list.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Alon Levy <alevy@redhat.com>
---
libcacard/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcacard/Makefile b/libcacard/Makefile
index 89a5942..b620c28 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -18,7 +18,7 @@ vscclient$(EXESUF): libcacard/vscclient.o libcacard.la
# Rules for building libcacard standalone library
libcacard.la: LDFLAGS += -rpath $(libdir) -no-undefined \
- -export-syms $(SRC_PATH)/libcacard/libcacard.syms
+ -export-symbols $(SRC_PATH)/libcacard/libcacard.syms
libcacard.la: LIBS = $(libcacard_libs)
libcacard.la: $(libcacard-lobj-y)
$(call LINK,$^)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-trivial] [PATCH v2 1/7] do not call g_thread_init() for glib >= 2.31
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
@ 2014-05-03 9:11 ` Michael Tokarev
-1 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-03 9:11 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Stefan Hajnoczi
02.05.2014 18:35, Michael Tokarev wrote:
> glib >= 2.31 always enables thread support and g_thread_supported()
> is #defined to 1, there's no need to call g_thread_init() anymore,
> and it definitely does not need to report error which never happens.
> Keep code for old < 2.31 glibc anyway for now, just #ifdef it
> differently.
Applied to -trivial, thanks!
/mjt
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: qemu-trivial@nongnu.org
> ---
> coroutine-gthread.c | 7 ++-----
> util/osdep.c | 21 +++++++++------------
> 2 files changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/coroutine-gthread.c b/coroutine-gthread.c
> index d3e5b99..a61efe0 100644
> --- a/coroutine-gthread.c
> +++ b/coroutine-gthread.c
> @@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
>
> static void __attribute__((constructor)) coroutine_init(void)
> {
> - if (!g_thread_supported()) {
> #if !GLIB_CHECK_VERSION(2, 31, 0)
> + if (!g_thread_supported()) {
> g_thread_init(NULL);
> -#else
> - fprintf(stderr, "glib threading failed to initialize.\n");
> - exit(1);
> -#endif
> }
> +#endif
>
> init_coroutine_cond();
> }
> diff --git a/util/osdep.c b/util/osdep.c
> index a9029f8..b2bd154 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -436,23 +436,20 @@ int socket_init(void)
> return 0;
> }
>
> -/* Ensure that glib is running in multi-threaded mode */
> +#if !GLIB_CHECK_VERSION(2, 31, 0)
> +/* Ensure that glib is running in multi-threaded mode
> + * Old versions of glib require explicit initialization. Failure to do
> + * this results in the single-threaded code paths being taken inside
> + * glib. For example, the g_slice allocator will not be thread-safe
> + * and cause crashes.
> + */
> static void __attribute__((constructor)) thread_init(void)
> {
> if (!g_thread_supported()) {
> -#if !GLIB_CHECK_VERSION(2, 31, 0)
> - /* Old versions of glib require explicit initialization. Failure to do
> - * this results in the single-threaded code paths being taken inside
> - * glib. For example, the g_slice allocator will not be thread-safe
> - * and cause crashes.
> - */
> - g_thread_init(NULL);
> -#else
> - fprintf(stderr, "glib threading failed to initialize.\n");
> - exit(1);
> -#endif
> + g_thread_init(NULL);
> }
> }
> +#endif
>
> #ifndef CONFIG_IOVEC
> /* helper function for iov_send_recv() */
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 1/7] do not call g_thread_init() for glib >= 2.31
@ 2014-05-03 9:11 ` Michael Tokarev
0 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-03 9:11 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Stefan Hajnoczi
02.05.2014 18:35, Michael Tokarev wrote:
> glib >= 2.31 always enables thread support and g_thread_supported()
> is #defined to 1, there's no need to call g_thread_init() anymore,
> and it definitely does not need to report error which never happens.
> Keep code for old < 2.31 glibc anyway for now, just #ifdef it
> differently.
Applied to -trivial, thanks!
/mjt
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: qemu-trivial@nongnu.org
> ---
> coroutine-gthread.c | 7 ++-----
> util/osdep.c | 21 +++++++++------------
> 2 files changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/coroutine-gthread.c b/coroutine-gthread.c
> index d3e5b99..a61efe0 100644
> --- a/coroutine-gthread.c
> +++ b/coroutine-gthread.c
> @@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
>
> static void __attribute__((constructor)) coroutine_init(void)
> {
> - if (!g_thread_supported()) {
> #if !GLIB_CHECK_VERSION(2, 31, 0)
> + if (!g_thread_supported()) {
> g_thread_init(NULL);
> -#else
> - fprintf(stderr, "glib threading failed to initialize.\n");
> - exit(1);
> -#endif
> }
> +#endif
>
> init_coroutine_cond();
> }
> diff --git a/util/osdep.c b/util/osdep.c
> index a9029f8..b2bd154 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -436,23 +436,20 @@ int socket_init(void)
> return 0;
> }
>
> -/* Ensure that glib is running in multi-threaded mode */
> +#if !GLIB_CHECK_VERSION(2, 31, 0)
> +/* Ensure that glib is running in multi-threaded mode
> + * Old versions of glib require explicit initialization. Failure to do
> + * this results in the single-threaded code paths being taken inside
> + * glib. For example, the g_slice allocator will not be thread-safe
> + * and cause crashes.
> + */
> static void __attribute__((constructor)) thread_init(void)
> {
> if (!g_thread_supported()) {
> -#if !GLIB_CHECK_VERSION(2, 31, 0)
> - /* Old versions of glib require explicit initialization. Failure to do
> - * this results in the single-threaded code paths being taken inside
> - * glib. For example, the g_slice allocator will not be thread-safe
> - * and cause crashes.
> - */
> - g_thread_init(NULL);
> -#else
> - fprintf(stderr, "glib threading failed to initialize.\n");
> - exit(1);
> -#endif
> + g_thread_init(NULL);
> }
> }
> +#endif
>
> #ifndef CONFIG_IOVEC
> /* helper function for iov_send_recv() */
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-trivial] [PATCH v2 2/7] glib: move g_poll() replacement into glib-compat.h
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
@ 2014-05-03 9:11 ` Michael Tokarev
-1 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-03 9:11 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Stefan Hajnoczi
02.05.2014 18:35, Michael Tokarev wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> We have a dedicated header file for wrappers to smooth over glib version
> differences. Move the g_poll() definition into glib-compat.h for
> consistency.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> Cc: qemu-trivial@nongnu.org
Applied to -trivial, thanks!
/mjt
> include/glib-compat.h | 12 ++++++++++++
> include/qemu-common.h | 12 ------------
> 2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index 8aa77af..8d25900 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -24,4 +24,16 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
> }
> #endif
>
> +#if !GLIB_CHECK_VERSION(2, 20, 0)
> +/*
> + * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
> + * on older systems.
> + */
> +static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
> +{
> + GMainContext *ctx = g_main_context_default();
> + return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
> +}
> +#endif
> +
> #endif
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index a998e8d..3f3fd60 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -124,18 +124,6 @@ int qemu_main(int argc, char **argv, char **envp);
> void qemu_get_timedate(struct tm *tm, int offset);
> int qemu_timedate_diff(struct tm *tm);
>
> -#if !GLIB_CHECK_VERSION(2, 20, 0)
> -/*
> - * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
> - * on older systems.
> - */
> -static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
> -{
> - GMainContext *ctx = g_main_context_default();
> - return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
> -}
> -#endif
> -
> /**
> * is_help_option:
> * @s: string to test
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 2/7] glib: move g_poll() replacement into glib-compat.h
@ 2014-05-03 9:11 ` Michael Tokarev
0 siblings, 0 replies; 15+ messages in thread
From: Michael Tokarev @ 2014-05-03 9:11 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Stefan Hajnoczi
02.05.2014 18:35, Michael Tokarev wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> We have a dedicated header file for wrappers to smooth over glib version
> differences. Move the g_poll() definition into glib-compat.h for
> consistency.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> Cc: qemu-trivial@nongnu.org
Applied to -trivial, thanks!
/mjt
> include/glib-compat.h | 12 ++++++++++++
> include/qemu-common.h | 12 ------------
> 2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index 8aa77af..8d25900 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -24,4 +24,16 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
> }
> #endif
>
> +#if !GLIB_CHECK_VERSION(2, 20, 0)
> +/*
> + * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
> + * on older systems.
> + */
> +static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
> +{
> + GMainContext *ctx = g_main_context_default();
> + return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
> +}
> +#endif
> +
> #endif
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index a998e8d..3f3fd60 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -124,18 +124,6 @@ int qemu_main(int argc, char **argv, char **envp);
> void qemu_get_timedate(struct tm *tm, int offset);
> int qemu_timedate_diff(struct tm *tm);
>
> -#if !GLIB_CHECK_VERSION(2, 20, 0)
> -/*
> - * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
> - * on older systems.
> - */
> -static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
> -{
> - GMainContext *ctx = g_main_context_default();
> - return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
> -}
> -#endif
> -
> /**
> * is_help_option:
> * @s: string to test
>
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-05-03 9:12 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-02 14:35 [Qemu-devel] [PATCH v2 0/7] glib thread interface and libcacard cleanups Michael Tokarev
2014-05-02 14:35 ` [Qemu-trivial] [PATCH v2 1/7] do not call g_thread_init() for glib >= 2.31 Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
2014-05-03 9:11 ` [Qemu-trivial] " Michael Tokarev
2014-05-03 9:11 ` [Qemu-devel] " Michael Tokarev
2014-05-02 14:35 ` [Qemu-trivial] [PATCH v2 2/7] glib: move g_poll() replacement into glib-compat.h Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
2014-05-03 9:11 ` [Qemu-trivial] " Michael Tokarev
2014-05-03 9:11 ` [Qemu-devel] " Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] [PATCH v2 3/7] glib-compat.h: add new thread API emulation on top of pre-2.31 API Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] [PATCH v2 4/7] vscclient: use glib thread primitives not qemu Michael Tokarev
2014-05-02 14:35 ` [Qemu-trivial] [PATCH v2 5/7] libcacard: replace pstrcpy() with memcpy() Michael Tokarev
2014-05-02 14:35 ` [Qemu-devel] " Michael Tokarev
2014-05-02 14:36 ` [Qemu-devel] [PATCH v2 6/7] libcacard: replace qemu thread primitives with glib ones Michael Tokarev
2014-05-02 14:36 ` [Qemu-devel] [PATCH v2 7/7] libcacard: actually use symbols file Michael Tokarev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.