From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrQtf-0000hY-Hu for qemu-devel@nongnu.org; Fri, 13 Dec 2013 06:27:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrQtZ-0007OY-H1 for qemu-devel@nongnu.org; Fri, 13 Dec 2013 06:27:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrQtZ-0007OT-89 for qemu-devel@nongnu.org; Fri, 13 Dec 2013 06:27:01 -0500 From: Stefan Hajnoczi Date: Fri, 13 Dec 2013 11:11:08 +0100 Message-Id: <1386929468-10023-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v2] trace: add glib 2.32+ static GMutex support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Michael Tokarev , "Dr. David Alan Gilbert" The GStaticMutex API was deprecated in glib 2.32. We cannot switch over to GMutex unconditionally since we would drop support for older glib versions. But the deprecated API warnings during build are annoying so use static GMutex when possible. Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/trace/simple.c b/trace/simple.c index 1e3f691..40ce448 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -39,7 +39,17 @@ * 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) @@ -139,27 +149,26 @@ static bool get_trace_record(unsigned int idx, TraceRecord **recordptr) */ static void flush_trace_file(bool wait) { - g_static_mutex_lock(&trace_lock); + lock_trace_lock(); trace_available = true; g_cond_signal(trace_available_cond); if (wait) { - g_cond_wait(trace_empty_cond, g_static_mutex_get_mutex(&trace_lock)); + g_cond_wait(trace_empty_cond, get_trace_lock_mutex()); } - g_static_mutex_unlock(&trace_lock); + unlock_trace_lock(); } static void wait_for_trace_records_available(void) { - g_static_mutex_lock(&trace_lock); + lock_trace_lock(); while (!(trace_available && trace_writeout_enabled)) { g_cond_signal(trace_empty_cond); - g_cond_wait(trace_available_cond, - g_static_mutex_get_mutex(&trace_lock)); + g_cond_wait(trace_available_cond, get_trace_lock_mutex()); } trace_available = false; - g_static_mutex_unlock(&trace_lock); + unlock_trace_lock(); } static gpointer writeout_thread(gpointer opaque) -- 1.8.4.2