From 1e6968c9607550e765a0d1a5568e16d20fe956e3 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Tue, 20 Jun 2017 15:52:16 +0300 Subject: [PATCH] mutex-posix: log unlock failure reason Bug 101497 shows a mutex unlock failure in a client application. To debug the problem, it would be useful to see the failure reason in the log. BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=101497 --- src/pulsecore/mutex-posix.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/mutex-posix.c b/src/pulsecore/mutex-posix.c index a835be1b7..6e00ec37b 100644 --- a/src/pulsecore/mutex-posix.c +++ b/src/pulsecore/mutex-posix.c @@ -25,6 +25,8 @@ #include #include + +#include #include #include "mutex.h" @@ -103,9 +105,17 @@ bool pa_mutex_try_lock(pa_mutex *m) { } void pa_mutex_unlock(pa_mutex *m) { + int r; + pa_assert(m); - pa_assert_se(pthread_mutex_unlock(&m->mutex) == 0); + if ((r = pthread_mutex_unlock(&m->mutex) != 0)) { + /* We don't use pa_cstrerror() here, because it uses a mutex itself, + * and mutexes seem to be misbehaving. strerror() is not thread-safe, + * but it's better than nothing. */ + pa_log("pthread_mutex_unlock() failed: %s", strerror(r)); + pa_assert_not_reached(); + } } pa_cond *pa_cond_new(void) { -- 2.11.0