[glib] gthread: Emit a critical if g_rw_lock_reader_lock() fails
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gthread: Emit a critical if g_rw_lock_reader_lock() fails
- Date: Fri, 3 Nov 2017 19:22:35 +0000 (UTC)
commit fc817eb38af6381c8c439a1460c61a91774def53
Author: Philip Withnall <withnall endlessm com>
Date: Fri Nov 3 15:24:44 2017 +0000
gthread: Emit a critical if g_rw_lock_reader_lock() fails
It can only fail if there’s been a leak or programmer error, so this is
really unlikely to happen. At least make it obvious something has gone
wrong, though, rather than silently carrying on and returning as if the
reader lock has been acquired.
Do the same for g_rw_lock_writer_lock().
It should be safe to use g_critical() for reporting the problems, since
GRWLock is not used in gmessages.c, and printing a critical seems better
than aborting, just in case we do hit the ‘maximum number of reader
locks’ error code.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=756430
glib/gthread-posix.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 44d804f..4d69660 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -538,7 +538,10 @@ g_rw_lock_clear (GRWLock *rw_lock)
void
g_rw_lock_writer_lock (GRWLock *rw_lock)
{
- pthread_rwlock_wrlock (g_rw_lock_get_impl (rw_lock));
+ int retval = pthread_rwlock_wrlock (g_rw_lock_get_impl (rw_lock));
+
+ if (retval != 0)
+ g_critical ("Failed to get RW lock %p: %s", rw_lock, g_strerror (retval));
}
/**
@@ -588,14 +591,18 @@ g_rw_lock_writer_unlock (GRWLock *rw_lock)
* thread will block. Read locks can be taken recursively.
*
* It is implementation-defined how many threads are allowed to
- * hold read locks on the same lock simultaneously.
+ * hold read locks on the same lock simultaneously. If the limit is hit,
+ * or if a deadlock is detected, a critical warning will be emitted.
*
* Since: 2.32
*/
void
g_rw_lock_reader_lock (GRWLock *rw_lock)
{
- pthread_rwlock_rdlock (g_rw_lock_get_impl (rw_lock));
+ int retval = pthread_rwlock_rdlock (g_rw_lock_get_impl (rw_lock));
+
+ if (retval != 0)
+ g_critical ("Failed to get RW lock %p: %s", rw_lock, g_strerror (retval));
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]