2 This file is part of PulseAudio.
4 Copyright 2008 Lennart Poettering
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.1 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 <pulsecore/macro.h>
30 #include <pulsecore/thread.h>
31 #include <pulsecore/lock-autospawn.h>
32 #include <pulse/util.h>
34 static void thread_func(void*k) {
35 pa_assert_se(pa_autospawn_lock_init() >= 0);
37 pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
39 pa_assert_se(pa_autospawn_lock_acquire(TRUE) > 0);
41 pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k));
45 pa_log("%i, Releasing", PA_PTR_TO_INT(k));
47 pa_autospawn_lock_release();
49 pa_autospawn_lock_done(FALSE);
52 static void thread_func2(void *k) {
55 pa_assert_se((fd = pa_autospawn_lock_init()) >= 0);
57 pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
63 if ((j = pa_autospawn_lock_acquire(FALSE)) > 0)
68 memset(&pollfd, 0, sizeof(pollfd));
70 pollfd.events = POLLIN;
72 pa_assert_se(poll(&pollfd, 1, -1) == 1);
74 pa_log("%i, woke up", PA_PTR_TO_INT(k));
77 pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k));
81 pa_log("%i, Releasing", PA_PTR_TO_INT(k));
83 pa_autospawn_lock_release();
85 pa_autospawn_lock_done(FALSE);
88 int main(int argc, char**argv) {
89 pa_thread *a, *b, *c, *d;
91 pa_assert_se((a = pa_thread_new(thread_func, PA_INT_TO_PTR(1))));
92 pa_assert_se((b = pa_thread_new(thread_func2, PA_INT_TO_PTR(2))));
93 pa_assert_se((c = pa_thread_new(thread_func2, PA_INT_TO_PTR(3))));
94 pa_assert_se((d = pa_thread_new(thread_func, PA_INT_TO_PTR(4))));