summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-02-03 14:57:33 +0100
committerOlivier Goffart <olivier.goffart@nokia.com>2011-02-03 16:20:24 +0100
commitba8e5eedf5f40091eb67dd391a7dcaf9299db2f5 (patch)
tree8b0f86781af6386c70526b5f5d10dc82f3c44eaf /src/corelib/thread
parent6f313a63d4155b53659917a3f7a71f4de60d0d91 (diff)
Implement QThreadData::current using __thread
It slightly faster, and QThreadData::current is used everywhere Reviewed-by: mread Reviewed-by: Joao
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread_unix.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 0766447fd4..891ac77004 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -110,6 +110,17 @@ QT_BEGIN_NAMESPACE
enum { ThreadPriorityResetFlag = 0x80000000 };
+#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (defined(Q_CC_GNU) || defined(Q_CC_INTEL))
+#define HAVE_TLS
+#endif
+#if defined(Q_CC_XLC) || defined (Q_CC_SUN)
+#define HAVE_TLS
+#endif
+
+#ifdef HAVE_TLS
+static __thread QThreadData *currentThreadData = 0;
+#endif
+
static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT;
static pthread_key_t current_thread_data_key;
@@ -157,7 +168,9 @@ Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key)
// that pthread has, so pthread_setspecific is also used.
static QThreadData *get_thread_data()
{
-#ifdef Q_OS_SYMBIAN
+#ifdef HAVE_TLS
+ return currentThreadData;
+#elif defined Q_OS_SYMBIAN
return reinterpret_cast<QThreadData *>(Dll::Tls());
#else
pthread_once(&current_thread_data_once, create_current_thread_data_key);
@@ -167,7 +180,9 @@ static QThreadData *get_thread_data()
static void set_thread_data(QThreadData *data)
{
-#ifdef Q_OS_SYMBIAN
+#ifdef HAVE_TLS
+ currentThreadData = data;
+#elif defined Q_OS_SYMBIAN
qt_symbian_throwIfError(Dll::SetTls(data));
#endif
pthread_once(&current_thread_data_once, create_current_thread_data_key);
@@ -176,7 +191,9 @@ static void set_thread_data(QThreadData *data)
static void clear_thread_data()
{
-#ifdef Q_OS_SYMBIAN
+#ifdef HAVE_TLS
+ currentThreadData = 0;
+#elif defined Q_OS_SYMBIAN
Dll::FreeTls();
#endif
pthread_setspecific(current_thread_data_key, 0);