[glib] Fix bug in g_static_rec_mutex_unlock_full()
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Fix bug in g_static_rec_mutex_unlock_full()
- Date: Wed, 19 Oct 2011 03:32:06 +0000 (UTC)
commit 99f0eaa4c5a86f6fa721044bb6841f6bda4c689b
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Oct 18 23:26:00 2011 -0400
Fix bug in g_static_rec_mutex_unlock_full()
pthreads doesn't implement the _lock_full() and _unlock_full() calls on
recursive mutexes so we don't have it on GRecMutex either. Now that
we're using GRecMutex to implement GStaticRecMutex, we have to fake it
by keeping an internal counter of the number of locks and calling
g_rec_mutex_unlock() the appropriate number of times.
The code to do this looked like:
depth = mutex->depth;
while (mutex->depth--)
g_rec_mutex_unlock (rm);
return depth;
which unfortunately did one last decrement after mutex->depth was
already zero (leaving it equal to -1).
When locked the next time, the count would then increase from -1 to 0
and then the next _unlock_full() call would not do any calls to
g_rec_mutex_unlock(), leading to a deadlock.
https://bugzilla.gnome.org/show_bug.cgi?id=661914
glib/deprecated/gthread-deprecated.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/glib/deprecated/gthread-deprecated.c b/glib/deprecated/gthread-deprecated.c
index cb685e3..b53dfce 100644
--- a/glib/deprecated/gthread-deprecated.c
+++ b/glib/deprecated/gthread-deprecated.c
@@ -806,8 +806,11 @@ g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex)
rm = g_static_rec_mutex_get_rec_mutex_impl (mutex);
depth = mutex->depth;
- while (mutex->depth--)
- g_rec_mutex_unlock (rm);
+ while (mutex->depth)
+ {
+ mutex->depth--;
+ g_rec_mutex_unlock (rm);
+ }
return depth;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]