]> code.delx.au - pulseaudio/blob - src/pulsecore/flist.h
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / flist.h
1 #ifndef foopulseflisthfoo
2 #define foopulseflisthfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2006-2008 Lennart Poettering
8
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.
13
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.
18
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
22 USA.
23 ***/
24
25 #include <pulse/def.h>
26 #include <pulse/gccmacro.h>
27
28 #include <pulsecore/once.h>
29 #include <pulsecore/core-util.h>
30
31 /* A multiple-reader multipler-write lock-free free list implementation */
32
33 typedef struct pa_flist pa_flist;
34
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);
40
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);
44
45 /* Please note that the destructor stuff is not really necessary, we do
46 * this just to make valgrind output more useful. */
47
48 #define PA_STATIC_FLIST_DECLARE(name, size, free_cb) \
49 static struct { \
50 pa_flist *volatile flist; \
51 pa_once once; \
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); \
56 } \
57 static inline pa_flist* name##_flist_get(void) { \
58 pa_run_once(&name##_flist.once, name##_flist_init); \
59 return name##_flist.flist; \
60 } \
61 static void name##_flist_destructor(void) PA_GCC_DESTRUCTOR; \
62 static void name##_flist_destructor(void) { \
63 if (!pa_in_valgrind()) \
64 return; \
65 if (name##_flist.flist) \
66 pa_flist_free(name##_flist.flist, (free_cb)); \
67 } \
68 struct __stupid_useless_struct_to_allow_trailing_semicolon
69
70 #define PA_STATIC_FLIST_GET(name) (name##_flist_get())
71
72 #endif