summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2019-08-14 08:05:53 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2019-08-20 00:32:31 +0200
commitdcdfb6908db0f83cbc4e550859f56ee58a6b3420 (patch)
tree0b9347804e124037363223a389f4ac23cad0c745
parentd8a9bec35fb0c60a0e5990c1a12ffe6f39fdbf2d (diff)
Remove workaround for compilers not supporting thread_local
With C++11, all compilers support thread_local, which replaces the non- standardized __thread attribute as a storage class. The storage class was specifically introduced so that applications do not have to deal with pthread APIs for TLS key management. We still need to have some of that logic for adopting foreign threads, but we can rely on thread_local so that we get a fast implementation of QThread::currentThread() on all platforms. Change-Id: Iba2b35d014044c4ab317a0e127c5d1f1fa4ecd4a Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/thread/qthread_unix.cpp23
1 files changed, 1 insertions, 22 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 38e9c1c3ec..cb3c0d6bb1 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -108,20 +108,8 @@ Q_STATIC_ASSERT(sizeof(pthread_t) <= sizeof(Qt::HANDLE));
enum { ThreadPriorityResetFlag = 0x80000000 };
-#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (defined(Q_CC_GNU) || defined(Q_CC_INTEL)) && !defined(QT_LINUXBASE)
-/* LSB doesn't have __thread, https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=993 */
-#define HAVE_TLS
-#endif
-#if defined(Q_CC_XLC) || defined (Q_CC_SUN)
-#define HAVE_TLS
-#endif
-#if defined(Q_OS_RTEMS)
-#define HAVE_TLS
-#endif
-#ifdef HAVE_TLS
-static __thread QThreadData *currentThreadData = 0;
-#endif
+static thread_local QThreadData *currentThreadData = 0;
static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT;
static pthread_key_t current_thread_data_key;
@@ -182,28 +170,19 @@ Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key)
// Utility functions for getting, setting and clearing thread specific data.
static QThreadData *get_thread_data()
{
-#ifdef HAVE_TLS
return currentThreadData;
-#else
- pthread_once(&current_thread_data_once, create_current_thread_data_key);
- return reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key));
-#endif
}
static void set_thread_data(QThreadData *data)
{
-#ifdef HAVE_TLS
currentThreadData = data;
-#endif
pthread_once(&current_thread_data_once, create_current_thread_data_key);
pthread_setspecific(current_thread_data_key, data);
}
static void clear_thread_data()
{
-#ifdef HAVE_TLS
currentThreadData = 0;
-#endif
pthread_setspecific(current_thread_data_key, 0);
}