diff --git a/glib/gbitlock.c b/glib/gbitlock.c index a9f7a5ea2..a7d335cc1 100644 --- a/glib/gbitlock.c +++ b/glib/gbitlock.c @@ -36,17 +36,10 @@ #endif #ifndef HAVE_FUTEX +static GStaticMutex g_futex_mutex = G_STATIC_MUTEX_INIT; static GSList *g_futex_address_list = NULL; -static GMutex *g_futex_mutex = NULL; #endif -void -_g_futex_thread_init (void) { -#ifndef HAVE_FUTEX - g_futex_mutex = g_mutex_new (); -#endif -} - #ifdef HAVE_FUTEX /* * We have headers for futex(2) on the build machine. This does not @@ -131,7 +124,7 @@ static void g_futex_wait (const volatile gint *address, gint value) { - g_mutex_lock (g_futex_mutex); + g_static_mutex_lock (&g_futex_mutex); if G_LIKELY (g_atomic_int_get (address) == value) { WaitAddress *waiter; @@ -147,7 +140,7 @@ g_futex_wait (const volatile gint *address, } waiter->ref_count++; - g_cond_wait (waiter->wait_queue, g_futex_mutex); + g_cond_wait (waiter->wait_queue, g_static_mutex_get_mutex (&g_futex_mutex)); if (!--waiter->ref_count) { @@ -157,7 +150,7 @@ g_futex_wait (const volatile gint *address, g_slice_free (WaitAddress, waiter); } } - g_mutex_unlock (g_futex_mutex); + g_static_mutex_unlock (&g_futex_mutex); } static void @@ -171,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_mutex_lock (g_futex_mutex); + g_static_mutex_lock (&g_futex_mutex); if ((waiter = g_futex_find_address (address))) g_cond_signal (waiter->wait_queue); - g_mutex_unlock (g_futex_mutex); + g_static_mutex_unlock (&g_futex_mutex); } #endif diff --git a/glib/gthread.c b/glib/gthread.c index bc993892d..6edec630d 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -963,7 +963,6 @@ g_thread_init_glib (void) _g_rand_thread_init (); _g_main_thread_init (); _g_utils_thread_init (); - _g_futex_thread_init (); } /* The following sections implement: GOnce, GStaticMutex, GStaticRecMutex, diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h index e7f0ce4f7..8ee465b31 100644 --- a/glib/gthreadprivate.h +++ b/glib/gthreadprivate.h @@ -58,7 +58,6 @@ G_GNUC_INTERNAL void _g_rand_thread_init (void); G_GNUC_INTERNAL void _g_main_thread_init (void); G_GNUC_INTERNAL void _g_atomic_thread_init (void); G_GNUC_INTERNAL void _g_utils_thread_init (void); -G_GNUC_INTERNAL void _g_futex_thread_init (void); G_GNUC_INTERNAL void _g_thread_impl_init (void); G_END_DECLS diff --git a/gthread/tests/1bit-mutex.c b/gthread/tests/1bit-mutex.c index 0bfce91f0..c5377564a 100644 --- a/gthread/tests/1bit-mutex.c +++ b/gthread/tests/1bit-mutex.c @@ -42,7 +42,6 @@ #define g_pointer_bit_lock _emufutex_g_pointer_bit_lock #define g_pointer_bit_trylock _emufutex_g_pointer_bit_trylock #define g_pointer_bit_unlock _emufutex_g_pointer_bit_unlock - #define _g_futex_thread_init _emufutex_g_futex_thread_init #define G_BIT_LOCK_FORCE_FUTEX_EMULATION @@ -121,13 +120,12 @@ testcase (gconstpointer data) g_thread_init (NULL); #ifdef TEST_EMULATED_FUTEX - _g_futex_thread_init (); #define SUFFIX "-emufutex" /* ensure that we are using the emulated futex by checking - * (at compile-time) for the existance of 'g_futex_mutex' + * (at compile-time) for the existance of 'g_futex_address_list' */ - g_assert (g_futex_mutex != NULL); + g_assert (g_futex_address_list == NULL); #else #define SUFFIX "" #endif