[pulseaudio-commits] r1856 - /branches/lennart/src/pulsecore/mutex-posix.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Tue Sep 18 12:51:27 PDT 2007
Author: lennart
Date: Tue Sep 18 21:51:26 2007
New Revision: 1856
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1856&root=pulseaudio&view=rev
Log:
If PTHREAD_PRIO_INHERIT mutexes are not available fall back to normal mutexes
Modified:
branches/lennart/src/pulsecore/mutex-posix.c
Modified: branches/lennart/src/pulsecore/mutex-posix.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/mutex-posix.c?rev=1856&root=pulseaudio&r1=1855&r2=1856&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/mutex-posix.c (original)
+++ branches/lennart/src/pulsecore/mutex-posix.c Tue Sep 18 21:51:26 2007
@@ -26,9 +26,12 @@
#endif
#include <pthread.h>
+#include <errno.h>
#include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-error.h>
#include "mutex.h"
@@ -43,19 +46,36 @@
pa_mutex* pa_mutex_new(pa_bool_t recursive, pa_bool_t inherit_priority) {
pa_mutex *m;
pthread_mutexattr_t attr;
+ int r;
- pthread_mutexattr_init(&attr);
+ pa_assert_se(pthread_mutexattr_init(&attr) == 0);
if (recursive)
pa_assert_se(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);
#ifdef HAVE_PTHREAD_PRIO_INHERIT
if (inherit_priority)
- pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
+ pa_assert_se(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) == 0);
#endif
m = pa_xnew(pa_mutex, 1);
+
+#ifndef HAVE_PTHREAD_PRIO_INHERIT
pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);
+
+#else
+ if ((r = pthread_mutex_init(&m->mutex, &attr))) {
+
+ /* If this failed, then this was probably due to non-available
+ * priority inheritance. In which case we fall back to normal
+ * mutexes. */
+ pa_assert(r == ENOTSUP && inherit_priority);
+
+ pa_assert_se(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_NONE) == 0);
+ pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);
+ }
+#endif
+
return m;
}
More information about the pulseaudio-commits
mailing list