Branch data Line data Source code
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 <pulsecore/asyncmsgq.h>
29 : : #include <pulsecore/thread.h>
30 : : #include <pulsecore/log.h>
31 : : #include <pulsecore/macro.h>
32 : :
33 : : enum {
34 : : OPERATION_A,
35 : : OPERATION_B,
36 : : OPERATION_C,
37 : : QUIT
38 : : };
39 : :
40 : 1 : static void the_thread(void *_q) {
41 : 1 : pa_asyncmsgq *q = _q;
42 : 1 : int quit = 0;
43 : :
44 : : do {
45 : 4 : int code = 0;
46 : :
47 [ - + ]: 4 : pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0);
48 : :
49 [ + + + + : 4 : switch (code) {
- ]
50 : :
51 : : case OPERATION_A:
52 : 1 : pa_log_info("Operation A");
53 : 1 : break;
54 : :
55 : : case OPERATION_B:
56 : 1 : pa_log_info("Operation B");
57 : 1 : break;
58 : :
59 : : case OPERATION_C:
60 : 1 : pa_log_info("Operation C");
61 : 1 : break;
62 : :
63 : : case QUIT:
64 : 1 : pa_log_info("quit");
65 : 1 : quit = 1;
66 : 1 : break;
67 : : }
68 : :
69 : 4 : pa_asyncmsgq_done(q, 0);
70 : :
71 [ + + ]: 4 : } while (!quit);
72 : 1 : }
73 : :
74 : 1 : int main(int argc, char *argv[]) {
75 : : pa_asyncmsgq *q;
76 : : pa_thread *t;
77 : :
78 [ - + ]: 1 : pa_assert_se(q = pa_asyncmsgq_new(0));
79 : :
80 [ - + ]: 1 : pa_assert_se(t = pa_thread_new("test", the_thread, q));
81 : :
82 : 1 : pa_log_info("Operation A post");
83 : 1 : pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL);
84 : :
85 : 1 : pa_thread_yield();
86 : :
87 : 1 : pa_log_info("Operation B post");
88 : 1 : pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL);
89 : :
90 : 1 : pa_thread_yield();
91 : :
92 : 1 : pa_log_info("Operation C send");
93 : 1 : pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL);
94 : :
95 : 1 : pa_thread_yield();
96 : :
97 : 1 : pa_log_info("Quit post");
98 : 1 : pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL);
99 : :
100 : 1 : pa_thread_free(t);
101 : :
102 : 1 : pa_asyncmsgq_unref(q);
103 : :
104 : : return 0;
105 : : }
|