1 #ifndef foopulseflisthfoo
2 #define foopulseflisthfoo
5 This file is part of PulseAudio.
7 Copyright 2006-2008 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <pulse/def.h>
26 #include <pulse/gccmacro.h>
28 #include <pulsecore/once.h>
29 #include <pulsecore/core-util.h>
31 /* A multiple-reader multipler-write lock-free free list implementation */
33 typedef struct pa_flist pa_flist
;
35 pa_flist
* pa_flist_new(unsigned size
);
36 /* Name string is copied and added to flist structure. The original is
37 * responsibility of the caller. The name is only used for debug printing. */
38 pa_flist
* pa_flist_new_with_name(unsigned size
, const char *name
);
39 void pa_flist_free(pa_flist
*l
, pa_free_cb_t free_cb
);
41 /* Please note that this routine might fail! */
42 int pa_flist_push(pa_flist
*l
, void *p
);
43 void* pa_flist_pop(pa_flist
*l
);
45 /* Please not that the destructor stuff is not really necesary, we do
46 * this just to make valgrind output more useful. */
48 #define PA_STATIC_FLIST_DECLARE(name, size, free_cb) \
50 pa_flist *volatile flist; \
52 } name##_flist = { NULL, PA_ONCE_INIT }; \
53 static void name##_flist_init(void) { \
54 name##_flist.flist = \
55 pa_flist_new_with_name(size, __FILE__ ": " #name); \
57 static inline pa_flist* name##_flist_get(void) { \
58 pa_run_once(&name##_flist.once, name##_flist_init); \
59 return name##_flist.flist; \
61 static void name##_flist_destructor(void) PA_GCC_DESTRUCTOR; \
62 static void name##_flist_destructor(void) { \
63 if (!pa_in_valgrind()) \
65 if (name##_flist.flist) \
66 pa_flist_free(name##_flist.flist, (free_cb)); \
68 struct __stupid_useless_struct_to_allow_trailing_semicolon
70 #define PA_STATIC_FLIST_GET(name) (name##_flist_get())