]>
code.delx.au - pulseaudio/blob - src/pulsecore/mutex-posix.c
4 This file is part of PulseAudio.
6 Copyright 2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
31 #include <pulsecore/macro.h>
36 pthread_mutex_t mutex
;
43 pa_mutex
* pa_mutex_new(int recursive
) {
45 pthread_mutexattr_t attr
;
47 pthread_mutexattr_init(&attr
);
50 pa_assert_se(pthread_mutexattr_settype(&attr
, PTHREAD_MUTEX_RECURSIVE
) == 0);
52 m
= pa_xnew(pa_mutex
, 1);
53 pa_assert_se(pthread_mutex_init(&m
->mutex
, &attr
) == 0);
57 void pa_mutex_free(pa_mutex
*m
) {
60 pa_assert_se(pthread_mutex_destroy(&m
->mutex
) == 0);
64 void pa_mutex_lock(pa_mutex
*m
) {
67 pa_assert_se(pthread_mutex_lock(&m
->mutex
) == 0);
70 void pa_mutex_unlock(pa_mutex
*m
) {
73 pa_assert_se(pthread_mutex_unlock(&m
->mutex
) == 0);
76 pa_cond
*pa_cond_new(void) {
79 c
= pa_xnew(pa_cond
, 1);
80 pa_assert_se(pthread_cond_init(&c
->cond
, NULL
) == 0);
84 void pa_cond_free(pa_cond
*c
) {
87 pa_assert_se(pthread_cond_destroy(&c
->cond
) == 0);
91 void pa_cond_signal(pa_cond
*c
, int broadcast
) {
95 pa_assert_se(pthread_cond_broadcast(&c
->cond
) == 0);
97 pa_assert_se(pthread_cond_signal(&c
->cond
) == 0);
100 int pa_cond_wait(pa_cond
*c
, pa_mutex
*m
) {
104 return pthread_cond_wait(&c
->cond
, &m
->mutex
);