Revert "pacat: Don't use any buffer attr if we don't set any latency/process time...
[pulseaudio-mirror.git] / src / tests / flist-test.c
blob64c0add22f85c7238dbf3411f3f4b2039e50cdfa
1 /***
2 This file is part of PulseAudio.
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.
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.
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 ***/
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <unistd.h>
28 #include <pulse/util.h>
29 #include <pulse/xmalloc.h>
30 #include <pulsecore/flist.h>
31 #include <pulsecore/thread.h>
32 #include <pulsecore/log.h>
33 #include <pulsecore/core-util.h>
35 #define THREADS_MAX 20
37 static pa_flist *flist;
38 static int quit = 0;
40 static void spin(void) {
41 int k;
43 /* Spin a little */
44 k = rand() % 10000;
45 for (; k > 0; k--)
46 pa_thread_yield();
49 static void thread_func(void *data) {
50 char *s = data;
51 int n = 0;
52 int b = 1;
54 while (!quit) {
55 char *text;
57 /* Allocate some memory, if possible take it from the flist */
58 if (b && (text = pa_flist_pop(flist)))
59 pa_log("%s: popped '%s'", s, text);
60 else {
61 text = pa_sprintf_malloc("Block %i, allocated by %s", n++, s);
62 pa_log("%s: allocated '%s'", s, text);
65 b = !b;
67 spin();
69 /* Give it back to the flist if possible */
70 if (pa_flist_push(flist, text) < 0) {
71 pa_log("%s: failed to push back '%s'", s, text);
72 pa_xfree(text);
73 } else
74 pa_log("%s: pushed", s);
76 spin();
79 if (pa_flist_push(flist, s) < 0)
80 pa_xfree(s);
83 int main(int argc, char* argv[]) {
84 pa_thread *threads[THREADS_MAX];
85 int i;
87 flist = pa_flist_new(0);
89 for (i = 0; i < THREADS_MAX; i++) {
90 threads[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1));
91 assert(threads[i]);
94 pa_msleep(60000);
95 quit = 1;
97 for (i = 0; i < THREADS_MAX; i++)
98 pa_thread_free(threads[i]);
100 pa_flist_free(flist, pa_xfree);
102 return 0;