1 #ifndef foopulsethreadhfoo
2 #define foopulsethreadhfoo
7 This file is part of PulseAudio.
9 Copyright 2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
12 PulseAudio is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 PulseAudio is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with PulseAudio; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/def.h>
29 #include <pulsecore/once.h>
32 #error "Please include config.h before including this file!"
35 typedef struct pa_thread pa_thread
;
37 typedef void (*pa_thread_func_t
) (void *userdata
);
39 pa_thread
* pa_thread_new(pa_thread_func_t thread_func
, void *userdata
);
40 void pa_thread_free(pa_thread
*t
);
41 int pa_thread_join(pa_thread
*t
);
42 int pa_thread_is_running(pa_thread
*t
);
43 pa_thread
*pa_thread_self(void);
44 void pa_thread_yield(void);
46 void* pa_thread_get_data(pa_thread
*t
);
47 void pa_thread_set_data(pa_thread
*t
, void *userdata
);
49 typedef struct pa_tls pa_tls
;
51 pa_tls
* pa_tls_new(pa_free_cb_t free_cb
);
52 void pa_tls_free(pa_tls
*t
);
53 void * pa_tls_get(pa_tls
*t
);
54 void *pa_tls_set(pa_tls
*t
, void *userdata
);
56 #define PA_STATIC_TLS_DECLARE(name, free_cb) \
61 .once = PA_ONCE_INIT, \
64 static void name##_tls_init(void) { \
65 name##_tls.tls = pa_tls_new(free_cb); \
67 static inline pa_tls* name##_tls_obj(void) { \
68 pa_run_once(&name##_tls.once, name##_tls_init); \
69 return name##_tls.tls; \
71 static void name##_tls_destructor(void) PA_GCC_DESTRUCTOR; \
72 static void name##_tls_destructor(void) { \
74 pa_tls_free(name##_tls.tls); \
76 static inline void* name##_tls_get(void) { \
77 return pa_tls_get(name##_tls_obj()); \
79 static inline void* name##_tls_set(void *p) { \
80 return pa_tls_set(name##_tls_obj(), p); \
82 struct __stupid_useless_struct_to_allow_trailing_semicolon
84 #ifdef HAVE_TLS_BUILTIN
85 /* An optimized version of the above that requires no dynamic
86 * allocation if the compiler supports __thread */
87 #define PA_STATIC_TLS_DECLARE_NO_FREE(name) \
88 static __thread void *name##_tls; \
89 static inline void* name##_tls_get(void) { \
92 static inline void* name##_tls_set(void *p) { \
93 void *r = name##_tls; \
97 struct __stupid_useless_struct_to_allow_trailing_semicolon
99 #define PA_STATIC_TLS_DECLARE_NO_FREE(name) PA_STATIC_TLS_DECLARE(name, NULL)
102 #define PA_STATIC_TLS_GET(name) (name##_tls_get())
103 #define PA_STATIC_TLS_SET(name, p) (name##_tls_set(p))