libglib: stop using g_cond_new in some places

Port a couple of low-level users of g_cond_new to use G_COND_INIT or
g_cond_init() as appropriate.
This commit is contained in:
Ryan Lortie 2011-09-17 18:05:24 -04:00
parent 22b3e26034
commit f1d34d0187
2 changed files with 11 additions and 15 deletions

View File

@ -31,9 +31,8 @@
#include "gthreadprivate.h" #include "gthreadprivate.h"
#include "config.h" #include "config.h"
#ifdef G_BIT_LOCK_FORCE_FUTEX_EMULATION
#undef HAVE_FUTEX #undef HAVE_FUTEX
#ifdef G_BIT_LOCK_FORCE_FUTEX_EMULATION
#endif #endif
#ifndef HAVE_FUTEX #ifndef HAVE_FUTEX
@ -102,7 +101,7 @@ typedef struct
{ {
const volatile gint *address; const volatile gint *address;
gint ref_count; gint ref_count;
GCond *wait_queue; GCond wait_queue;
} WaitAddress; } WaitAddress;
static WaitAddress * static WaitAddress *
@ -134,20 +133,20 @@ g_futex_wait (const volatile gint *address,
{ {
waiter = g_slice_new (WaitAddress); waiter = g_slice_new (WaitAddress);
waiter->address = address; waiter->address = address;
waiter->wait_queue = g_cond_new (); g_cond_init (&waiter->wait_queue);
waiter->ref_count = 0; waiter->ref_count = 0;
g_futex_address_list = g_futex_address_list =
g_slist_prepend (g_futex_address_list, waiter); g_slist_prepend (g_futex_address_list, waiter);
} }
waiter->ref_count++; waiter->ref_count++;
g_cond_wait (waiter->wait_queue, &g_futex_mutex); g_cond_wait (&waiter->wait_queue, &g_futex_mutex);
if (!--waiter->ref_count) if (!--waiter->ref_count)
{ {
g_futex_address_list = g_futex_address_list =
g_slist_remove (g_futex_address_list, waiter); g_slist_remove (g_futex_address_list, waiter);
g_cond_free (waiter->wait_queue); g_cond_clear (&waiter->wait_queue);
g_slice_free (WaitAddress, waiter); g_slice_free (WaitAddress, waiter);
} }
} }
@ -167,7 +166,7 @@ g_futex_wake (const volatile gint *address)
*/ */
g_mutex_lock (&g_futex_mutex); g_mutex_lock (&g_futex_mutex);
if ((waiter = g_futex_find_address (address))) if ((waiter = g_futex_find_address (address)))
g_cond_signal (waiter->wait_queue); g_cond_signal (&waiter->wait_queue);
g_mutex_unlock (&g_futex_mutex); g_mutex_unlock (&g_futex_mutex);
} }
#endif #endif

View File

@ -875,7 +875,7 @@ static GThreadFunctions g_thread_functions_for_glib_use_old = {
/* Local Data {{{1 -------------------------------------------------------- */ /* Local Data {{{1 -------------------------------------------------------- */
static GMutex g_once_mutex = G_MUTEX_INIT; static GMutex g_once_mutex = G_MUTEX_INIT;
static GCond *g_once_cond = NULL; static GCond g_once_cond = G_COND_INIT;
static GPrivate *g_thread_specific_private = NULL; static GPrivate *g_thread_specific_private = NULL;
static GRealThread *g_thread_all_threads = NULL; static GRealThread *g_thread_all_threads = NULL;
static GSList *g_thread_free_indices = NULL; static GSList *g_thread_free_indices = NULL;
@ -940,9 +940,6 @@ g_thread_init_glib (void)
*/ */
GRealThread* main_thread = (GRealThread*) g_thread_self (); GRealThread* main_thread = (GRealThread*) g_thread_self ();
/* mutex and cond creation works without g_threads_got_initialized */
g_once_cond = g_cond_new ();
/* we may only create mutex and cond in here */ /* we may only create mutex and cond in here */
_g_mem_thread_init_noprivate_nomessage (); _g_mem_thread_init_noprivate_nomessage ();
@ -1049,7 +1046,7 @@ g_once_impl (GOnce *once,
g_mutex_lock (&g_once_mutex); g_mutex_lock (&g_once_mutex);
while (once->status == G_ONCE_STATUS_PROGRESS) while (once->status == G_ONCE_STATUS_PROGRESS)
g_cond_wait (g_once_cond, &g_once_mutex); g_cond_wait (&g_once_cond, &g_once_mutex);
if (once->status != G_ONCE_STATUS_READY) if (once->status != G_ONCE_STATUS_READY)
{ {
@ -1060,7 +1057,7 @@ g_once_impl (GOnce *once,
g_mutex_lock (&g_once_mutex); g_mutex_lock (&g_once_mutex);
once->status = G_ONCE_STATUS_READY; once->status = G_ONCE_STATUS_READY;
g_cond_broadcast (g_once_cond); g_cond_broadcast (&g_once_cond);
} }
g_mutex_unlock (&g_once_mutex); g_mutex_unlock (&g_once_mutex);
@ -1116,7 +1113,7 @@ g_once_init_enter_impl (volatile gsize *value_location)
} }
else else
do do
g_cond_wait (g_once_cond, &g_once_mutex); g_cond_wait (&g_once_cond, &g_once_mutex);
while (g_slist_find (g_once_init_list, (void*) value_location)); while (g_slist_find (g_once_init_list, (void*) value_location));
} }
g_mutex_unlock (&g_once_mutex); g_mutex_unlock (&g_once_mutex);
@ -1148,7 +1145,7 @@ g_once_init_leave (volatile gsize *value_location,
g_atomic_pointer_set (value_location, initialization_value); g_atomic_pointer_set (value_location, initialization_value);
g_mutex_lock (&g_once_mutex); g_mutex_lock (&g_once_mutex);
g_once_init_list = g_slist_remove (g_once_init_list, (void*) value_location); g_once_init_list = g_slist_remove (g_once_init_list, (void*) value_location);
g_cond_broadcast (g_once_cond); g_cond_broadcast (&g_once_cond);
g_mutex_unlock (&g_once_mutex); g_mutex_unlock (&g_once_mutex);
} }