mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
emufutex: remove init from g_thread_init_glib
Use a GStaticMutex instead.
This commit is contained in:
parent
80109acef5
commit
413186a962
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user