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 <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 : 1 : static void producer(void *_q) {
35 : 1 : pa_asyncq *q = _q;
36 : : int i;
37 : :
38 [ + + ]: 1001 : for (i = 0; i < 1000; i++) {
39 : 1000 : pa_log_debug("pushing %i", i);
40 : 1000 : pa_asyncq_push(q, PA_UINT_TO_PTR(i+1), 1);
41 : : }
42 : :
43 : 1 : pa_asyncq_push(q, PA_UINT_TO_PTR(-1), TRUE);
44 : 1 : pa_log_debug("pushed end");
45 : 1 : }
46 : :
47 : 1 : static void consumer(void *_q) {
48 : 1 : pa_asyncq *q = _q;
49 : : void *p;
50 : : int i;
51 : :
52 : 1 : pa_msleep(1000);
53 : :
54 : 1 : for (i = 0;; i++) {
55 : 1001 : p = pa_asyncq_pop(q, TRUE);
56 : :
57 [ + + ]: 1001 : if (p == PA_UINT_TO_PTR(-1))
58 : : break;
59 : :
60 [ - + ]: 1000 : pa_assert(p == PA_UINT_TO_PTR(i+1));
61 : :
62 : 1000 : pa_log_debug("popped %i", i);
63 : 1000 : }
64 : :
65 : 1 : pa_log_debug("popped end");
66 : 1 : }
67 : :
68 : 1 : int main(int argc, char *argv[]) {
69 : : pa_asyncq *q;
70 : : pa_thread *t1, *t2;
71 : :
72 [ - + ]: 1 : if (!getenv("MAKE_CHECK"))
73 : 0 : pa_log_set_level(PA_LOG_DEBUG);
74 : :
75 [ - + ]: 1 : pa_assert_se(q = pa_asyncq_new(0));
76 : :
77 [ - + ]: 1 : pa_assert_se(t1 = pa_thread_new("producer", producer, q));
78 [ - + ]: 1 : pa_assert_se(t2 = pa_thread_new("consumer", consumer, q));
79 : :
80 : 1 : pa_thread_free(t1);
81 : 1 : pa_thread_free(t2);
82 : :
83 : 1 : pa_asyncq_free(q, NULL);
84 : :
85 : : return 0;
86 : : }
|