]> code.delx.au - pulseaudio/blob - src/tests/asyncq-test.c
Remove unnecessary #includes
[pulseaudio] / src / tests / asyncq-test.c
1 /***
2 This file is part of PulseAudio.
3
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
8
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27
28 #include <pulse/util.h>
29 #include <pulsecore/asyncq.h>
30 #include <pulsecore/thread.h>
31 #include <pulsecore/log.h>
32 #include <pulsecore/macro.h>
33
34 static void producer(void *_q) {
35 pa_asyncq *q = _q;
36 int i;
37
38 for (i = 0; i < 1000; i++) {
39 printf("pushing %i\n", i);
40 pa_asyncq_push(q, PA_UINT_TO_PTR(i+1), 1);
41 }
42
43 pa_asyncq_push(q, PA_UINT_TO_PTR(-1), TRUE);
44 printf("pushed end\n");
45 }
46
47 static void consumer(void *_q) {
48 pa_asyncq *q = _q;
49 void *p;
50 int i;
51
52 pa_msleep(1000);
53
54 for (i = 0;; i++) {
55 p = pa_asyncq_pop(q, TRUE);
56
57 if (p == PA_UINT_TO_PTR(-1))
58 break;
59
60 pa_assert(p == PA_UINT_TO_PTR(i+1));
61
62 printf("popped %i\n", i);
63 }
64
65 printf("popped end\n");
66 }
67
68 int main(int argc, char *argv[]) {
69 pa_asyncq *q;
70 pa_thread *t1, *t2;
71
72 pa_assert_se(q = pa_asyncq_new(0));
73
74 pa_assert_se(t1 = pa_thread_new("producer", producer, q));
75 pa_assert_se(t2 = pa_thread_new("consumer", consumer, q));
76
77 pa_thread_free(t1);
78 pa_thread_free(t2);
79
80 pa_asyncq_free(q, NULL);
81
82 return 0;
83 }