diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-08-22 00:19:33 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-08-22 00:19:33 +0000 |
commit | a0ad42a35f73a9bdc0751cbb902f01da2c3c4b05 (patch) | |
tree | 5936be08fb45087a27d4149a7beba40324663ee8 | |
parent | b0b06b0002fc9eb14f2a151796d547543bec6b9b (diff) |
add macro for creating static TLS objects
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1683 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | src/pulsecore/thread.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pulsecore/thread.h b/src/pulsecore/thread.h index ca1fe4da..44b80a06 100644 --- a/src/pulsecore/thread.h +++ b/src/pulsecore/thread.h @@ -48,4 +48,30 @@ void pa_tls_free(pa_tls *t); void * pa_tls_get(pa_tls *t); void *pa_tls_set(pa_tls *t, void *userdata); +/* To make use of the static TLS stuff you have to include once.h, as well */ + +#define PA_STATIC_TLS_DECLARE(name, free_cb) \ + static struct { \ + pa_once once; \ + pa_tls *tls; \ + } name##_tls = { \ + .once = PA_ONCE_INIT, \ + .tls = NULL \ + }; \ + static void name##_tls_init(void) { \ + name##_tls.tls = pa_tls_new(free_cb); \ + } \ + static inline pa_tls* name##_tls_get(void) { \ + pa_run_once(&name##_tls.once, name##_tls_init); \ + return name##_tls.tls; \ + } \ + static void name##_tls_destructor(void) PA_GCC_DESTRUCTOR; \ + static void name##_tls_destructor(void) { \ + if (name##_tls.tls) \ + pa_tls_free(name##_tls.tls); \ + } \ + struct __stupid_useless_struct_to_allow_trailing_semicolon + +#define PA_STATIC_TLS_GET(name) (name##_tls_get()) + #endif |