Patch by Sebastian Wilhemi to fix infinite recursion in g_atomic.
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 5 Mar 2004 21:10:45 +0000 (21:10 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 5 Mar 2004 21:10:45 +0000 (21:10 +0000)
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gatomic.c
glib/gthread.c
glib/gthreadinit.h

index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index b8b048513ce2922d5fe1f4aa88d7b75397c02c3e..324b33ead701981c1a23019e935cf6890657c0b2 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-05  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gatomic.c: Fix infinite recursion for
+       G_MEMORY_BARRIER_NEEDED and DEFINE_WITH_MUTEXES by using a GMutex
+       instead of G_DEFINE_LOCK. The mutex is allocated by the new
+       function _g_atomic_thread_init. Fixes #136284.
+
+       * glib/gthreadinit.h, glib/gthread.c: Declare and call
+       _g_atomic_thread_init during thread system initialization.
 2004-03-05  Tor Lillqvist  <tml@iki.fi>
 
        * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin)
index 9796cd5588c051da1ad5c9766fcb17cc6587acc2..65ad743e407f0986d35ddf53e12f3831f150b4b9 100644 (file)
@@ -466,17 +466,18 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
 
 #ifdef DEFINE_WITH_MUTEXES
 /* We have to use the slow, but safe locking method */
-G_LOCK_DEFINE_STATIC (g_atomic_lock);
+static GMutex *g_atomic_mutex; 
+
 gint
 g_atomic_int_exchange_and_add (gint *atomic, 
                               gint  val)
 {
   gint result;
     
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   result = *atomic;
   *atomic += val;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 
   return result;
 }
@@ -486,9 +487,9 @@ void
 g_atomic_int_add (gint *atomic,
                  gint  val)
 {
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   *atomic += val;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 }
 
 gboolean
@@ -498,7 +499,7 @@ g_atomic_int_compare_and_exchange (gint *atomic,
 {
   gboolean result;
     
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   if (*atomic == oldval)
     {
       result = TRUE;
@@ -506,7 +507,7 @@ g_atomic_int_compare_and_exchange (gint *atomic,
     }
   else
     result = FALSE;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 
   return result;
 }
@@ -518,7 +519,7 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
 {
   gboolean result;
     
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   if (*atomic == oldval)
     {
       result = TRUE;
@@ -526,7 +527,7 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
     }
   else
     result = FALSE;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 
   return result;
 }
@@ -537,9 +538,9 @@ g_atomic_int_get (gint *atomic)
 {
   gint result;
 
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   result = *atomic;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 
   return result;
 }
@@ -549,9 +550,9 @@ g_atomic_pointer_get (gpointer *atomic)
 {
   gpointer result;
 
-  G_LOCK (g_atomic_lock);
+  g_mutex_lock (g_atomic_mutex);
   result = *atomic;
-  G_UNLOCK (g_atomic_lock);
+  g_mutex_unlock (g_atomic_mutex);
 
   return result;
 }
@@ -609,3 +610,11 @@ g_atomic_int_add (gint *atomic,
   while (!ATOMIC_INT_CMP_XCHG (atomic, result, result + val));
 }
 #endif /* ATOMIC_INT_CMP_XCHG */
+
+void 
+_g_atomic_thread_init ()
+{
+#ifdef DEFINE_WITH_MUTEXES
+  g_atomic_mutex = g_mutex_new ();
+#endif /* DEFINE_WITH_MUTEXES */
+}
index b136763cf9f2baf2cfc2ae5d96681c067e195ef3..c222beb08cae6d2bab7fb2ed8d541d439a5bdb4a 100644 (file)
@@ -153,7 +153,8 @@ g_thread_init_glib (void)
   _g_main_thread_init ();
   _g_mem_thread_init ();
   _g_messages_thread_init ();
-  
+  _g_atomic_thread_init ();
   g_threads_got_initialized = TRUE;
 
   g_thread_specific_private = g_private_new (g_thread_cleanup);
index c8a8e8b7cec4e0ac3546b019eb8949fcc5ebe0e5..663c422e8b8b68fdcac91b782dfe6ba3f1767981 100644 (file)
@@ -32,6 +32,7 @@ void _g_messages_thread_init (void);
 void _g_convert_thread_init (void);
 void _g_rand_thread_init (void);
 void _g_main_thread_init (void);
+void _g_atomic_thread_init (void);
 
 /* Are called from glib/gthread.c. Must only contain g_private_new calls */
 void _g_mem_thread_private_init (void);