Add a missing pa_xfree.
[pulseaudio.git] / src / tests / asyncmsgq-test.c
blob380c5e7f6ebf800045f37af67a3aae07c91fcac3
1 /* $Id$ */
3 /***
4 This file is part of PulseAudio.
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.
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
19 USA.
20 ***/
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <unistd.h>
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>
38 enum {
39 OPERATION_A,
40 OPERATION_B,
41 OPERATION_C,
42 QUIT
45 static void the_thread(void *_q) {
46 pa_asyncmsgq *q = _q;
47 int quit = 0;
49 do {
50 int code = 0;
52 pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0);
54 switch (code) {
56 case OPERATION_A:
57 printf("Operation A\n");
58 break;
60 case OPERATION_B:
61 printf("Operation B\n");
62 break;
64 case OPERATION_C:
65 printf("Operation C\n");
66 break;
68 case QUIT:
69 printf("quit\n");
70 quit = 1;
71 break;
74 pa_asyncmsgq_done(q, 0);
76 } while (!quit);
79 int main(int argc, char *argv[]) {
80 pa_asyncmsgq *q;
81 pa_thread *t;
83 pa_assert_se(q = pa_asyncmsgq_new(0));
85 pa_assert_se(t = pa_thread_new(the_thread, q));
87 printf("Operation A post\n");
88 pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL);
90 pa_thread_yield();
92 printf("Operation B post\n");
93 pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL);
95 pa_thread_yield();
97 printf("Operation C send\n");
98 pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL);
100 pa_thread_yield();
102 printf("Quit post\n");
103 pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL);
105 pa_thread_free(t);
107 pa_asyncmsgq_unref(q);
109 return 0;