[glib/wip/mutexes: 6/12] libglib: stop using g_cond_new in some places



commit 9379cff780f54e1fc9fdbc8c470c426d9f0b59c1
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Sep 17 18:05:24 2011 -0400

    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.

 glib/gbitlock.c |   13 ++++++-------
 glib/gthread.c  |   13 +++++--------
 2 files changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/glib/gbitlock.c b/glib/gbitlock.c
index 0a74bce..d7c20cf 100644
--- a/glib/gbitlock.c
+++ b/glib/gbitlock.c
@@ -30,9 +30,8 @@
 #include "gthreadprivate.h"
 #include "config.h"
 
-
-#ifdef G_BIT_LOCK_FORCE_FUTEX_EMULATION
 #undef HAVE_FUTEX
+#ifdef G_BIT_LOCK_FORCE_FUTEX_EMULATION
 #endif
 
 #ifndef HAVE_FUTEX
@@ -101,7 +100,7 @@ typedef struct
 {
   const volatile gint *address;
   gint                 ref_count;
-  GCond               *wait_queue;
+  GCond                wait_queue;
 } WaitAddress;
 
 static WaitAddress *
@@ -133,20 +132,20 @@ g_futex_wait (const volatile gint *address,
         {
           waiter = g_slice_new (WaitAddress);
           waiter->address = address;
-          waiter->wait_queue = g_cond_new ();
+          g_cond_init (&waiter->wait_queue);
           waiter->ref_count = 0;
           g_futex_address_list =
             g_slist_prepend (g_futex_address_list, waiter);
         }
 
       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)
         {
           g_futex_address_list =
             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);
         }
     }
@@ -166,7 +165,7 @@ g_futex_wake (const volatile gint *address)
    */
   g_mutex_lock (&g_futex_mutex);
   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);
 }
 #endif
diff --git a/glib/gthread.c b/glib/gthread.c
index e5caf9d..75f2af6 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -874,7 +874,7 @@ static GThreadFunctions g_thread_functions_for_glib_use_old = {
 /* Local Data {{{1 -------------------------------------------------------- */
 
 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 GRealThread *g_thread_all_threads = NULL;
 static GSList   *g_thread_free_indices = NULL;
@@ -939,9 +939,6 @@ g_thread_init_glib (void)
    */
   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 */
   _g_mem_thread_init_noprivate_nomessage ();
 
@@ -1048,7 +1045,7 @@ g_once_impl (GOnce       *once,
   g_mutex_lock (&g_once_mutex);
 
   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)
     {
@@ -1059,7 +1056,7 @@ g_once_impl (GOnce       *once,
 
       g_mutex_lock (&g_once_mutex);
       once->status = G_ONCE_STATUS_READY;
-      g_cond_broadcast (g_once_cond);
+      g_cond_broadcast (&g_once_cond);
     }
 
   g_mutex_unlock (&g_once_mutex);
@@ -1115,7 +1112,7 @@ g_once_init_enter_impl (volatile gsize *value_location)
         }
       else
         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));
     }
   g_mutex_unlock (&g_once_mutex);
@@ -1147,7 +1144,7 @@ g_once_init_leave (volatile gsize *value_location,
   g_atomic_pointer_set (value_location, initialization_value);
   g_mutex_lock (&g_once_mutex);
   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);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]