]> code.delx.au - pulseaudio/blob - src/tests/thread-mainloop-test.c
merge 'lennart' branch back into trunk.
[pulseaudio] / src / tests / thread-mainloop-test.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <stdio.h>
29
30 #include <pulse/timeval.h>
31 #include <pulse/util.h>
32 #include <pulse/thread-mainloop.h>
33
34 #include <pulsecore/gccmacro.h>
35 #include <pulsecore/macro.h>
36
37 static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
38 pa_assert_se(pa_threaded_mainloop_in_thread(userdata));
39 fprintf(stderr, "TIME EVENT START\n");
40 pa_threaded_mainloop_signal(userdata, 1);
41 fprintf(stderr, "TIME EVENT END\n");
42 }
43
44 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
45 pa_mainloop_api *a;
46 pa_threaded_mainloop *m;
47 struct timeval tv;
48
49 pa_assert_se(m = pa_threaded_mainloop_new());
50 pa_assert_se(a = pa_threaded_mainloop_get_api(m));
51
52 pa_threaded_mainloop_start(m);
53
54 pa_threaded_mainloop_lock(m);
55
56 pa_assert_se(!pa_threaded_mainloop_in_thread(m));
57
58 pa_gettimeofday(&tv);
59 tv.tv_sec += 5;
60 a->time_new(a, &tv, tcb, m);
61
62 fprintf(stderr, "waiting 5s (signal)\n");
63 pa_threaded_mainloop_wait(m);
64 fprintf(stderr, "wait completed\n");
65 pa_threaded_mainloop_accept(m);
66 fprintf(stderr, "signal accepted\n");
67
68 pa_threaded_mainloop_unlock(m);
69
70 fprintf(stderr, "waiting 5s (sleep)\n");
71 pa_msleep(5000);
72
73 fprintf(stderr, "shutting down\n");
74
75 pa_threaded_mainloop_stop(m);
76
77 pa_threaded_mainloop_free(m);
78 return 0;
79 }