g_mutex_init (&mutex->lock);
g_mutex_init (&mutex->recursion_lock);
g_atomic_int_set (&mutex->recursion_allowed, FALSE);
+ g_atomic_int_set (&mutex->recursion_pending, FALSE);
}
void
{
gboolean exchanged;
+ g_mutex_lock (&mutex->recursion_lock);
g_mutex_lock (&mutex->lock);
exchanged =
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE,
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE,
FALSE);
g_assert (exchanged);
- g_cond_broadcast (&mutex->recursion_wait_cond);
g_mutex_unlock (&mutex->lock);
+ g_mutex_unlock (&mutex->recursion_lock);
}
/* must be called with mutex->lock taken */
{
gboolean exchanged;
- g_mutex_lock (&mutex->recursion_lock);
exchanged =
g_atomic_int_compare_and_exchange (&mutex->recursion_allowed, FALSE,
TRUE);
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE,
FALSE);
g_assert (exchanged);
- g_cond_broadcast (&mutex->recursion_wait_cond);
g_mutex_unlock (&mutex->recursion_lock);
}
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE,
TRUE);
g_assert (exchanged);
- g_mutex_unlock (&mutex->recursion_lock);
}
void
{
g_mutex_lock (&mutex->recursion_lock);
if (!g_atomic_int_get (&mutex->recursion_allowed)) {
- /* If recursion is pending wait until it happened */
- while (g_atomic_int_get (&mutex->recursion_pending))
- g_cond_wait (&mutex->recursion_wait_cond, &mutex->recursion_lock);
-
- if (!g_atomic_int_get (&mutex->recursion_allowed)) {
- /* no recursion allowed, lock the proper mutex */
- g_mutex_lock (&mutex->lock);
- g_mutex_unlock (&mutex->recursion_lock);
- }
+ /* no recursion allowed, lock the proper mutex */
+ g_mutex_lock (&mutex->lock);
+ g_mutex_unlock (&mutex->recursion_lock);
}
}