Commit ab0031bf authored by Matthias Clasen's avatar Matthias Clasen

Patch by Sebastian Wilhemi to fix infinite recursion in g_atomic.

parent eba3e002
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)
......
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)
......
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)
......
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)
......
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)
......
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)
......
......@@ -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 */
}
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment