]> code.delx.au - pulseaudio/blob - src/tests/asyncmsgq-test.c
A lot of more work to get the lock-free stuff in place
[pulseaudio] / src / tests / asyncmsgq-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 <assert.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29
30 #include <pulse/util.h>
31 #include <pulse/xmalloc.h>
32 #include <pulsecore/asyncmsgq.h>
33 #include <pulsecore/thread.h>
34 #include <pulsecore/log.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/macro.h>
37
38 enum {
39 OPERATION_A,
40 OPERATION_B,
41 OPERATION_C,
42 QUIT
43 };
44
45 static void the_thread(void *_q) {
46 pa_asyncmsgq *q = _q;
47 int quit = 0;
48
49 do {
50 int code = 0;
51
52 pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, 1) == 0);
53
54 switch (code) {
55
56 case OPERATION_A:
57 printf("Operation A\n");
58 break;
59
60 case OPERATION_B:
61 printf("Operation B\n");
62 break;
63
64 case OPERATION_C:
65 printf("Operation C\n");
66 break;
67
68 case QUIT:
69 printf("quit\n");
70 quit = 1;
71 break;
72 }
73
74 pa_asyncmsgq_done(q, 0);
75
76 } while (!quit);
77 }
78
79 int main(int argc, char *argv[]) {
80 pa_asyncmsgq *q;
81 pa_thread *t;
82
83 pa_assert_se(q = pa_asyncmsgq_new(0));
84
85 pa_assert_se(t = pa_thread_new(the_thread, q));
86
87 printf("Operation A post\n");
88 pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, NULL, NULL);
89
90 pa_thread_yield();
91
92 printf("Operation B post\n");
93 pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, NULL, NULL);
94
95 pa_thread_yield();
96
97 printf("Operation C send\n");
98 pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, NULL);
99
100 pa_thread_yield();
101
102 printf("Quit post\n");
103 pa_asyncmsgq_post(q, NULL, QUIT, NULL, NULL, NULL);
104
105 pa_thread_free(t);
106
107 pa_asyncmsgq_free(q);
108
109 return 0;
110 }