• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, see <http://www.gnu.org/licenses/>.
21 ***/
22 
23 #include <pulse/def.h>
24 #include <pulse/gccmacro.h>
25 
26 #include <pulsecore/once.h>
27 #include <pulsecore/core-util.h>
28 
29 /* A multiple-reader multipler-write lock-free free list implementation */
30 
31 typedef struct pa_flist pa_flist;
32 
33 pa_flist * pa_flist_new(unsigned size);
34 /* Name string is copied and added to flist structure. The original is
35  * responsibility of the caller. The name is only used for debug printing. */
36 pa_flist * pa_flist_new_with_name(unsigned size, const char *name);
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 note that the destructor stuff is not really necessary, 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 *volatile flist;                                       \
49         pa_once once;                                                   \
50     } name##_flist = { NULL, PA_ONCE_INIT };                            \
51     static void name##_flist_init(void) {                               \
52         name##_flist.flist =                                            \
53             pa_flist_new_with_name(size, __FILE__ ": " #name);          \
54     }                                                                   \
55     static inline pa_flist* name##_flist_get(void) {                    \
56         pa_run_once(&name##_flist.once, name##_flist_init);             \
57         return name##_flist.flist;                                      \
58     }                                                                   \
59     static void name##_flist_destructor(void) PA_GCC_DESTRUCTOR;        \
60     static void name##_flist_destructor(void) {                         \
61         if (!pa_in_valgrind())                                          \
62             return;                                                     \
63         if (name##_flist.flist)                                         \
64             pa_flist_free(name##_flist.flist, (free_cb));               \
65     }                                                                   \
66     struct __stupid_useless_struct_to_allow_trailing_semicolon
67 
68 #define PA_STATIC_FLIST_GET(name) (name##_flist_get())
69 
70 #endif
71