ACX_PTHREAD
+AC_MSG_CHECKING([for PTHREAD_PRIO_INHERIT])
+AC_LANG_CONFTEST([AC_LANG_SOURCE([[
+#include <pthread.h>
+int main() { int i = PTHREAD_PRIO_INHERIT; }]])])
+$PTHREAD_CC conftest.c $PTHREAD_CFLAGS $CFLAGS $PTHREAD_LIBS -o conftest > /dev/null 2> /dev/null
+ret=$?
+rm -f conftest.o conftest
+
+if test $ret -eq 0 ; then
+ AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.])
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+fi
+
+
#### Large File-Support (LFS) ####
AC_SYS_LARGEFILE
}
static void libtool_init(void) {
- pa_assert_se(libtool_mutex = pa_mutex_new(1));
+ pa_assert_se(libtool_mutex = pa_mutex_new(TRUE, FALSE));
pa_assert_se(lt_dlmutex_register(libtool_lock, libtool_unlock, libtool_set_error, libtool_get_error) == 0);
pa_assert_se(lt_dlinit() == 0);
}
u->thread_info.master = u->master = NULL;
u->time_event = NULL;
u->adjust_time = DEFAULT_ADJUST_TIME;
- u->mutex = pa_mutex_new(0);
+ u->mutex = pa_mutex_new(FALSE, TRUE);
pa_thread_mq_init(&u->thread_mq, m->core->mainloop);
u->rtpoll = NULL;
u->thread = NULL;
return NULL;
}
- m->mutex = pa_mutex_new(1);
+ m->mutex = pa_mutex_new(TRUE, FALSE);
m->cond = pa_cond_new();
m->accept_cond = pa_cond_new();
m->thread = NULL;
PA_REFCNT_INIT(a);
pa_assert_se(a->asyncq = pa_asyncq_new(size));
- pa_assert_se(a->mutex = pa_mutex_new(0));
+ pa_assert_se(a->mutex = pa_mutex_new(FALSE, TRUE));
a->current = NULL;
return a;
p = pa_xnew(pa_mempool, 1);
- p->mutex = pa_mutex_new(1);
+ p->mutex = pa_mutex_new(TRUE, TRUE);
p->semaphore = pa_semaphore_new(0);
p->block_size = PA_PAGE_ALIGN(PA_MEMPOOL_SLOT_SIZE);
pa_assert(cb);
i = pa_xnew(pa_memimport, 1);
- i->mutex = pa_mutex_new(1);
+ i->mutex = pa_mutex_new(TRUE, TRUE);
i->pool = p;
i->segments = pa_hashmap_new(NULL, NULL);
i->blocks = pa_hashmap_new(NULL, NULL);
int pa_memimport_process_revoke(pa_memimport *i, uint32_t id) {
pa_memblock *b;
+ int ret = 0;
pa_assert(i);
pa_mutex_lock(i->mutex);
- if (!(b = pa_hashmap_get(i->blocks, PA_UINT32_TO_PTR(id))))
- return -1;
+ if (!(b = pa_hashmap_get(i->blocks, PA_UINT32_TO_PTR(id)))) {
+ ret = -1;
+ goto finish;
+ }
memblock_replace_import(b);
+finish:
pa_mutex_unlock(i->mutex);
- return 0;
+ return ret;
}
/* For sending blocks to other nodes */
return NULL;
e = pa_xnew(pa_memexport, 1);
- e->mutex = pa_mutex_new(1);
+ e->mutex = pa_mutex_new(TRUE, TRUE);
e->pool = p;
PA_LLIST_HEAD_INIT(struct memexport_slot, e->free_slots);
PA_LLIST_HEAD_INIT(struct memexport_slot, e->used_slots);
pthread_cond_t cond;
};
-pa_mutex* pa_mutex_new(int recursive) {
+pa_mutex* pa_mutex_new(pa_bool_t recursive, pa_bool_t inherit_priority) {
pa_mutex *m;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
-
+
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);
+#endif
+
m = pa_xnew(pa_mutex, 1);
pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);
return m;
USA.
***/
+#include <pulsecore/macro.h>
+
typedef struct pa_mutex pa_mutex;
-pa_mutex* pa_mutex_new(int recursive);
+/* Please think twice before enabling priority inheritance. This is no
+ * magic wand! Use it only when the potentially priorized threads are
+ * good candidates for it. Don't use this blindly! Also, note that
+ * only very few operating systems actually implement this, hence this
+ * is merely a hint. */
+pa_mutex* pa_mutex_new(pa_bool_t recursive, pa_bool_t inherit_priority);
+
void pa_mutex_free(pa_mutex *m);
void pa_mutex_lock(pa_mutex *m);
void pa_mutex_unlock(pa_mutex *m);
return 0;
}
- pa_assert_se(m = pa_mutex_new(0));
+ pa_assert_se(m = pa_mutex_new(FALSE, FALSE));
pa_mutex_lock(m);
if (pa_atomic_ptr_cmpxchg(&control->mutex, NULL, m))
assert(pa_thread_is_running(pa_thread_self()));
- mutex = pa_mutex_new(0);
+ mutex = pa_mutex_new(FALSE, FALSE);
cond1 = pa_cond_new();
cond2 = pa_cond_new();
tls = pa_tls_new(pa_xfree);