From ab0031bf0060acb38781b0cb8e855fb33dc444ad Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 5 Mar 2004 21:10:45 +0000 Subject: [PATCH] Patch by Sebastian Wilhemi to fix infinite recursion in g_atomic. --- ChangeLog | 10 ++++++++++ ChangeLog.pre-2-10 | 10 ++++++++++ ChangeLog.pre-2-12 | 10 ++++++++++ ChangeLog.pre-2-4 | 10 ++++++++++ ChangeLog.pre-2-6 | 10 ++++++++++ ChangeLog.pre-2-8 | 10 ++++++++++ glib/gatomic.c | 35 ++++++++++++++++++++++------------- glib/gthread.c | 3 ++- glib/gthreadinit.h | 1 + 9 files changed, 85 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8b048513..324b33ead 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b8b048513..324b33ead 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index b8b048513..324b33ead 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index b8b048513..324b33ead 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index b8b048513..324b33ead 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index b8b048513..324b33ead 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +2004-03-05 Sebastian Wilhelmi + + * 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 * glib/glib.def: Add g_main_depth. (#136221, Cedric Gustin) diff --git a/glib/gatomic.c b/glib/gatomic.c index 9796cd558..65ad743e4 100644 --- a/glib/gatomic.c +++ b/glib/gatomic.c @@ -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 */ +} diff --git a/glib/gthread.c b/glib/gthread.c index b136763cf..c222beb08 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -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); diff --git a/glib/gthreadinit.h b/glib/gthreadinit.h index c8a8e8b7c..663c422e8 100644 --- a/glib/gthreadinit.h +++ b/glib/gthreadinit.h @@ -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);