[pulseaudio-commits] r1797 - in /branches/lennart: configure.ac src/daemon/main.c src/pulsecore/atomic.h src/pulsecore/rtsig.c src/pulsecore/thread-mq.c src/pulsecore/thread-posix.c src/pulsecore/thread.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Sep 10 16:57:11 PDT 2007
Author: lennart
Date: Tue Sep 11 01:57:10 2007
New Revision: 1797
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1797&root=pulseaudio&view=rev
Log:
unify static TLS support, make use of gcc __thread attribute if available
Modified:
branches/lennart/configure.ac
branches/lennart/src/daemon/main.c
branches/lennart/src/pulsecore/atomic.h
branches/lennart/src/pulsecore/rtsig.c
branches/lennart/src/pulsecore/thread-mq.c
branches/lennart/src/pulsecore/thread-posix.c
branches/lennart/src/pulsecore/thread.h
Modified: branches/lennart/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/configure.ac?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/configure.ac (original)
+++ branches/lennart/configure.ac Tue Sep 11 01:57:10 2007
@@ -113,6 +113,18 @@
rm -f conftest.o conftest
if test $ret -eq 0 ; then
AC_DEFINE([HAVE_ATOMIC_BUILTINS], 1, [Have __sync_bool_compare_and_swap() and friends.])
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+fi
+
+AC_MSG_CHECKING([whether $CC knows __thread])
+AC_LANG_CONFTEST([static __thread int a = 6; int main() { a = 5; }])
+$CC conftest.c $CFLAGS -o conftest > /dev/null 2> /dev/null
+ret=$?
+rm -f conftest.o conftest
+if test $ret -eq 0 ; then
+ AC_DEFINE([HAVE_TLS_BUILTIN], 1, [Have __thread().])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
Modified: branches/lennart/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/main.c?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/daemon/main.c (original)
+++ branches/lennart/src/daemon/main.c Tue Sep 11 01:57:10 2007
@@ -324,14 +324,14 @@
pa_mutex_unlock(libtool_mutex);
}
-PA_STATIC_TLS_DECLARE(libtool_tls, NULL);
+PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls);
static void libtool_set_error(const char * error) {
- pa_tls_set(PA_STATIC_TLS_GET(libtool_tls), (char*) error);
+ PA_STATIC_TLS_SET(libtool_tls, (char*) error);
}
static const char *libtool_get_error(void) {
- return pa_tls_get(PA_STATIC_TLS_GET(libtool_tls));
+ return PA_STATIC_TLS_GET(libtool_tls);
}
static void libtool_init(void) {
Modified: branches/lennart/src/pulsecore/atomic.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/atomic.h?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/atomic.h (original)
+++ branches/lennart/src/pulsecore/atomic.h Tue Sep 11 01:57:10 2007
@@ -37,7 +37,7 @@
* libatomic_ops
*/
-/* We have to include config.h here, which sucks */
+/* We have to include config.h here (for the __sync stuff), which sucks */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
Modified: branches/lennart/src/pulsecore/rtsig.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/rtsig.c?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/rtsig.c (original)
+++ branches/lennart/src/pulsecore/rtsig.c Tue Sep 11 01:57:10 2007
@@ -71,13 +71,13 @@
int sig;
void *p;
- if ((p = pa_tls_get(PA_STATIC_TLS_GET(rtsig_tls))))
+ if ((p = PA_STATIC_TLS_GET(rtsig_tls)))
return PA_PTR_TO_INT(p);
if ((sig = pa_rtsig_get()) < 0)
return -1;
- pa_tls_set(PA_STATIC_TLS_GET(rtsig_tls), PA_INT_TO_PTR(sig));
+ PA_STATIC_TLS_SET(rtsig_tls, PA_INT_TO_PTR(sig));
return sig;
}
Modified: branches/lennart/src/pulsecore/thread-mq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/thread-mq.c?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/thread-mq.c (original)
+++ branches/lennart/src/pulsecore/thread-mq.c Tue Sep 11 01:57:10 2007
@@ -41,8 +41,7 @@
#include "thread-mq.h"
-static pa_once once = PA_ONCE_INIT;
-static pa_tls *tls;
+PA_STATIC_TLS_DECLARE_NO_FREE(thread_mq);
static void asyncmsgq_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
pa_thread_mq *q = userdata;
@@ -101,20 +100,15 @@
q->mainloop = NULL;
}
-static void init_tls(void) {
- tls = pa_tls_new(NULL);
-}
-
void pa_thread_mq_install(pa_thread_mq *q) {
pa_assert(q);
- pa_run_once(&once, init_tls);
- pa_tls_set(tls, q);
+ pa_assert(!(PA_STATIC_TLS_GET(thread_mq)));
+ PA_STATIC_TLS_SET(thread_mq, q);
}
pa_thread_mq *pa_thread_mq_get(void) {
- pa_run_once(&once, init_tls);
- return pa_tls_get(tls);
+ return PA_STATIC_TLS_GET(thread_mq);
}
int pa_thread_mq_process(pa_thread_mq *q) {
Modified: branches/lennart/src/pulsecore/thread-posix.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/thread-posix.c?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/thread-posix.c (original)
+++ branches/lennart/src/pulsecore/thread-posix.c Tue Sep 11 01:57:10 2007
@@ -49,9 +49,6 @@
pthread_key_t key;
};
-static pthread_key_t thread_key;
-static pthread_once_t thread_once = PTHREAD_ONCE_INIT;
-
static void thread_free_cb(void *p) {
pa_thread *t = p;
@@ -62,9 +59,7 @@
pa_xfree(t);
}
-static void thread_once_func(void) {
- pa_assert_se(pthread_key_create(&thread_key, thread_free_cb) == 0);
-}
+PA_STATIC_TLS_DECLARE(current_thread, thread_free_cb);
static void* internal_thread_func(void *userdata) {
pa_thread *t = userdata;
@@ -72,8 +67,7 @@
t->id = pthread_self();
- pthread_once(&thread_once, thread_once_func);
- pthread_setspecific(thread_key, t);
+ PA_STATIC_TLS_SET(current_thread, t);
pa_atomic_inc(&t->running);
t->thread_func(t->userdata);
@@ -130,11 +124,9 @@
pa_thread* pa_thread_self(void) {
pa_thread *t;
- pthread_once(&thread_once, thread_once_func);
-
- if ((t = pthread_getspecific(thread_key)))
+ if ((t = PA_STATIC_TLS_GET(current_thread)))
return t;
-
+
/* This is a foreign thread, let's create a pthread structure to
* make sure that we can always return a sensible pointer */
@@ -144,7 +136,7 @@
t->userdata = NULL;
pa_atomic_store(&t->running, 2);
- pthread_setspecific(thread_key, t);
+ PA_STATIC_TLS_SET(current_thread, t);
return t;
}
Modified: branches/lennart/src/pulsecore/thread.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/thread.h?rev=1797&root=pulseaudio&r1=1796&r2=1797&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/thread.h (original)
+++ branches/lennart/src/pulsecore/thread.h Tue Sep 11 01:57:10 2007
@@ -26,6 +26,12 @@
***/
#include <pulse/def.h>
+#include <pulsecore/once.h>
+
+/* We have to include config.h here (for the __tls stuff), which sucks */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
typedef struct pa_thread pa_thread;
@@ -48,8 +54,6 @@
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; \
@@ -61,7 +65,7 @@
static void name##_tls_init(void) { \
name##_tls.tls = pa_tls_new(free_cb); \
} \
- static inline pa_tls* name##_tls_get(void) { \
+ static inline pa_tls* name##_tls_obj(void) { \
pa_run_once(&name##_tls.once, name##_tls_init); \
return name##_tls.tls; \
} \
@@ -70,8 +74,33 @@
if (name##_tls.tls) \
pa_tls_free(name##_tls.tls); \
} \
+ static inline void* name##_tls_get(void) { \
+ return pa_tls_get(name##_tls_obj()); \
+ } \
+ static inline void* name##_tls_set(void *p) { \
+ return pa_tls_set(name##_tls_obj(), p); \
+ } \
struct __stupid_useless_struct_to_allow_trailing_semicolon
+#ifdef HAVE_TLS_BUILTIN
+/* An optimized version of the above that requires no dynamic
+ * allocation if the compiler supports __thread */
+#define PA_STATIC_TLS_DECLARE_NO_FREE(name) \
+ static __thread void *name##_tls; \
+ static inline void* name##_tls_get(void) { \
+ return name##_tls; \
+ } \
+ static inline void* name##_tls_set(void *p) { \
+ void *r = name##_tls; \
+ name##_tls = p; \
+ return r; \
+ } \
+ struct __stupid_useless_struct_to_allow_trailing_semicolon
+#else
+#define PA_STATIC_TLS_DECLARE_NO_FREE(name) PA_STATIC_TLS_DECLARE(name, NULL)
+#endif
+
#define PA_STATIC_TLS_GET(name) (name##_tls_get())
+#define PA_STATIC_TLS_SET(name, p) (name##_tls_set(p))
#endif
More information about the pulseaudio-commits
mailing list