4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <atomic_ops.h>
31 #include <pulse/xmalloc.h>
35 #define ASSERT_SUCCESS(x) do { \
41 pthread_mutex_t mutex;
48 pa_mutex* pa_mutex_new(int recursive) {
50 pthread_mutexattr_t attr;
52 pthread_mutexattr_init(&attr);
55 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) < 0)
58 m = pa_xnew(pa_mutex, 1);
60 if (pthread_mutex_init(&m->mutex, &attr) < 0) {
68 void pa_mutex_free(pa_mutex *m) {
71 ASSERT_SUCCESS(pthread_mutex_destroy(&m->mutex));
75 void pa_mutex_lock(pa_mutex *m) {
78 ASSERT_SUCCESS(pthread_mutex_lock(&m->mutex));
81 void pa_mutex_unlock(pa_mutex *m) {
84 ASSERT_SUCCESS(pthread_mutex_unlock(&m->mutex));
88 pa_cond *pa_cond_new(void) {
91 c = pa_xnew(pa_cond, 1);
93 if (pthread_cond_init(&c->cond, NULL) < 0) {
101 void pa_cond_free(pa_cond *c) {
104 ASSERT_SUCCESS(pthread_cond_destroy(&c->cond));
108 void pa_cond_signal(pa_cond *c, int broadcast) {
112 ASSERT_SUCCESS(pthread_cond_broadcast(&c->cond));
114 ASSERT_SUCCESS(pthread_cond_signal(&c->cond));
117 int pa_cond_wait(pa_cond *c, pa_mutex *m) {
121 return pthread_cond_wait(&c->cond, &m->mutex);