[pulseaudio-commits] r1683 - /branches/lennart/src/pulsecore/thread.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Aug 21 17:19:34 PDT 2007


Author: lennart
Date: Wed Aug 22 02:19:33 2007
New Revision: 1683

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1683&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add macro for creating static TLS objects

Modified:
    branches/lennart/src/pulsecore/thread.h

Modified: branches/lennart/src/pulsecore/thread.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
thread.h?rev=3D1683&root=3Dpulseaudio&r1=3D1682&r2=3D1683&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/thread.h (original)
+++ branches/lennart/src/pulsecore/thread.h Wed Aug 22 02:19:33 2007
@@ -48,4 +48,30 @@
 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 =3D {                                                    \
+        .once =3D PA_ONCE_INIT,                                           \
+        .tls =3D NULL                                                     \
+    };                                                                  \
+    static void name##_tls_init(void) {                                 \
+        name##_tls.tls =3D 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




More information about the pulseaudio-commits mailing list