[glib/wip/mutexes: 2/6] libglib: drop use of GStaticMutex
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/mutexes: 2/6] libglib: drop use of GStaticMutex
- Date: Sat, 17 Sep 2011 22:28:03 +0000 (UTC)
commit 7fb78ff9da0159e927d27d925105aeb5307880b4
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Sep 17 17:47:46 2011 -0400
libglib: drop use of GStaticMutex
Use GMutex directly instead.
glib/gbitlock.c | 12 ++++++------
glib/gmain.c | 19 +++++++++----------
2 files changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/glib/gbitlock.c b/glib/gbitlock.c
index a7d335c..0a74bce 100644
--- a/glib/gbitlock.c
+++ b/glib/gbitlock.c
@@ -36,7 +36,7 @@
#endif
#ifndef HAVE_FUTEX
-static GStaticMutex g_futex_mutex = G_STATIC_MUTEX_INIT;
+static GMutex g_futex_mutex = G_MUTEX_INIT;
static GSList *g_futex_address_list = NULL;
#endif
@@ -124,7 +124,7 @@ static void
g_futex_wait (const volatile gint *address,
gint value)
{
- g_static_mutex_lock (&g_futex_mutex);
+ g_mutex_lock (&g_futex_mutex);
if G_LIKELY (g_atomic_int_get (address) == value)
{
WaitAddress *waiter;
@@ -140,7 +140,7 @@ g_futex_wait (const volatile gint *address,
}
waiter->ref_count++;
- g_cond_wait (waiter->wait_queue, g_static_mutex_get_mutex (&g_futex_mutex));
+ g_cond_wait (waiter->wait_queue, &g_futex_mutex);
if (!--waiter->ref_count)
{
@@ -150,7 +150,7 @@ g_futex_wait (const volatile gint *address,
g_slice_free (WaitAddress, waiter);
}
}
- g_static_mutex_unlock (&g_futex_mutex);
+ g_mutex_unlock (&g_futex_mutex);
}
static void
@@ -164,10 +164,10 @@ g_futex_wake (const volatile gint *address)
* 2) need to -stay- locked until the end to ensure a wake()
* in another thread doesn't cause 'waiter' to stop existing
*/
- g_static_mutex_lock (&g_futex_mutex);
+ g_mutex_lock (&g_futex_mutex);
if ((waiter = g_futex_find_address (address)))
g_cond_signal (waiter->wait_queue);
- g_static_mutex_unlock (&g_futex_mutex);
+ g_mutex_unlock (&g_futex_mutex);
}
#endif
diff --git a/glib/gmain.c b/glib/gmain.c
index f20603d..e631db2 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -220,7 +220,7 @@ struct _GMainContext
/* The following lock is used for both the list of sources
* and the list of poll records
*/
- GStaticMutex mutex;
+ GMutex mutex;
GCond *cond;
GThread *owner;
guint owner_count;
@@ -309,8 +309,8 @@ struct _GSourcePrivate
GSource *parent_source;
};
-#define LOCK_CONTEXT(context) g_static_mutex_lock (&context->mutex)
-#define UNLOCK_CONTEXT(context) g_static_mutex_unlock (&context->mutex)
+#define LOCK_CONTEXT(context) g_mutex_lock (&context->mutex)
+#define UNLOCK_CONTEXT(context) g_mutex_unlock (&context->mutex)
#define G_THREAD_SELF g_thread_self ()
#define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
@@ -488,7 +488,7 @@ g_main_context_unref (GMainContext *context)
source = next;
}
- g_static_mutex_free (&context->mutex);
+ g_mutex_clear (&context->mutex);
g_ptr_array_free (context->pending_dispatches, TRUE);
g_free (context->cached_poll_array);
@@ -542,7 +542,7 @@ g_main_context_new (void)
context = g_new0 (GMainContext, 1);
- g_static_mutex_init (&context->mutex);
+ g_mutex_init (&context->mutex);
context->owner = NULL;
context->waiters = NULL;
@@ -2515,8 +2515,7 @@ g_main_context_release (GMainContext *context)
if (context->waiters)
{
GMainWaiter *waiter = context->waiters->data;
- gboolean loop_internal_waiter =
- (waiter->mutex == g_static_mutex_get_mutex (&context->mutex));
+ gboolean loop_internal_waiter = (waiter->mutex == &context->mutex);
context->waiters = g_slist_delete_link (context->waiters,
context->waiters);
if (!loop_internal_waiter)
@@ -2559,7 +2558,7 @@ g_main_context_wait (GMainContext *context,
if (context == NULL)
context = g_main_context_default ();
- loop_internal_waiter = (mutex == g_static_mutex_get_mutex (&context->mutex));
+ loop_internal_waiter = (mutex == &context->mutex);
if (!loop_internal_waiter)
LOCK_CONTEXT (context);
@@ -2958,7 +2957,7 @@ g_main_context_iterate (GMainContext *context,
got_ownership = g_main_context_wait (context,
context->cond,
- g_static_mutex_get_mutex (&context->mutex));
+ &context->mutex);
if (!got_ownership)
return FALSE;
@@ -3169,7 +3168,7 @@ g_main_loop_run (GMainLoop *loop)
while (loop->is_running && !got_ownership)
got_ownership = g_main_context_wait (loop->context,
loop->context->cond,
- g_static_mutex_get_mutex (&loop->context->mutex));
+ &loop->context->mutex);
if (!loop->is_running)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]