]> code.delx.au - pulseaudio/blob - src/pulsecore/flist.h
Merge commit 'origin/master-tx' into master-tx
[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 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 /* Size is required to be a power of two, or 0 for the default size */
36 pa_flist * pa_flist_new(unsigned size);
37 void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb);
38
39 /* Please note that this routine might fail! */
40 int pa_flist_push(pa_flist*l, void *p);
41 void* pa_flist_pop(pa_flist*l);
42
43 /* Please not that the destructor stuff is not really necesary, we do
44 * this just to make valgrind output more useful. */
45
46 #define PA_STATIC_FLIST_DECLARE(name, size, free_cb) \
47 static struct { \
48 pa_flist *flist; \
49 pa_once once; \
50 } name##_flist = { NULL, PA_ONCE_INIT }; \
51 static void name##_flist_init(void) { \
52 name##_flist.flist = pa_flist_new(size); \
53 } \
54 static inline pa_flist* name##_flist_get(void) { \
55 pa_run_once(&name##_flist.once, name##_flist_init); \
56 return name##_flist.flist; \
57 } \
58 static void name##_flist_destructor(void) PA_GCC_DESTRUCTOR; \
59 static void name##_flist_destructor(void) { \
60 if (!pa_in_valgrind()) \
61 return; \
62 if (name##_flist.flist) \
63 pa_flist_free(name##_flist.flist, (free_cb)); \
64 } \
65 struct __stupid_useless_struct_to_allow_trailing_semicolon
66
67 #define PA_STATIC_FLIST_GET(name) (name##_flist_get())
68
69 #endif