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
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
;
40 static void spin(void) {
49 static void thread_func(void *data
) {
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
);
61 text
= pa_sprintf_malloc("Block %i, allocated by %s", n
++, s
);
62 pa_log("%s: allocated '%s'", s
, text
);
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
);
74 pa_log("%s: pushed", s
);
79 if (pa_flist_push(flist
, s
) < 0)
83 int main(int argc
, char* argv
[]) {
84 pa_thread
*threads
[THREADS_MAX
];
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));
97 for (i
= 0; i
< THREADS_MAX
; i
++)
98 pa_thread_free(threads
[i
]);
100 pa_flist_free(flist
, pa_xfree
);