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
This commit is contained in:
Philip Withnall 2017-11-03 15:24:44 +00:00
parent f5e229c76d
commit fc817eb38a

View File

@ -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));
}
/**