]> code.delx.au - pulseaudio/blob - src/tests/thread-mainloop-test.c
fix include line for "core-util.h"
[pulseaudio] / src / tests / thread-mainloop-test.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio 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 polypaudio 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 polypaudio; 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 <assert.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <stdio.h>
30
31 #include <polypcore/gccmacro.h>
32 #include <polypcore/core-util.h>
33 #include <polyp/thread-mainloop.h>
34
35 static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
36 fprintf(stderr, "TIME EVENT START\n");
37 pa_threaded_mainloop_signal(userdata, 1);
38 fprintf(stderr, "TIME EVENT END\n");
39 }
40
41 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
42 pa_mainloop_api *a;
43 pa_threaded_mainloop *m;
44 struct timeval tv;
45
46 m = pa_threaded_mainloop_new();
47 assert(m);
48 a = pa_threaded_mainloop_get_api(m);
49 assert(a);
50
51 pa_threaded_mainloop_start(m);
52
53 pa_threaded_mainloop_lock(m);
54
55 pa_gettimeofday(&tv);
56 tv.tv_sec += 5;
57 a->time_new(a, &tv, tcb, m);
58
59 fprintf(stderr, "waiting 5s (signal)\n");
60 pa_threaded_mainloop_wait(m);
61 fprintf(stderr, "wait completed\n");
62 pa_threaded_mainloop_accept(m);
63 fprintf(stderr, "signal accepted\n");
64
65 pa_threaded_mainloop_unlock(m);
66
67 fprintf(stderr, "waiting 5s (sleep)\n");
68 pa_msleep(5000);
69
70 fprintf(stderr, "shutting down\n");
71
72 pa_threaded_mainloop_stop(m);
73
74 pa_threaded_mainloop_free(m);
75 return 0;
76 }