From b8b50c6c7a6df17db03ff6fd3a2501511e51703f Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Sat, 20 Mar 2021 18:35:59 +0100 Subject: Clenaup Q_COMPILER_THREADSAFE_STATICS Change-Id: I1cf0646d4e6c9b30a7ef6538d81f92faf2e511e1 Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 17 ++++--------- src/corelib/global/qglobalstatic.h | 43 --------------------------------- 2 files changed, 5 insertions(+), 55 deletions(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index d1ce56fd0a..cc48355ff0 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -378,7 +378,6 @@ # define Q_COMPILER_STATIC_ASSERT # define Q_COMPILER_TEMPLATE_ALIAS # define Q_COMPILER_THREAD_LOCAL -# define Q_COMPILER_THREADSAFE_STATICS # define Q_COMPILER_UDL # define Q_COMPILER_UNICODE_STRINGS # define Q_COMPILER_UNIFORM_INIT @@ -573,6 +572,11 @@ * Q_COMPILER_RESTRICTED_VLA variable-length arrays, prior to __cpp_runtime_arrays */ +/* + * Now that we require C++17, we unconditionally expect threadsafe statics mandated since C++11 + */ +#define Q_COMPILER_THREADSAFE_STATICS + #ifdef __cplusplus # if __cplusplus < 201103L && !defined(Q_CC_MSVC) # error Qt requires a C++11 compiler and yours does not seem to be that. @@ -582,7 +586,6 @@ #if defined(Q_CC_INTEL) && !defined(Q_CC_MSVC) # define Q_COMPILER_RESTRICTED_VLA # define Q_COMPILER_VARIADIC_MACROS // C++11 feature supported as an extension in other modes, too -# define Q_COMPILER_THREADSAFE_STATICS # if __INTEL_COMPILER < 1200 # define Q_NO_TEMPLATE_FRIENDS # endif @@ -658,7 +661,6 @@ #if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !defined(Q_CC_MSVC) /* General C++ features */ # define Q_COMPILER_RESTRICTED_VLA -# define Q_COMPILER_THREADSAFE_STATICS # if __has_feature(attribute_deprecated_with_message) # define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text))) # endif @@ -826,7 +828,6 @@ #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) # define Q_COMPILER_RESTRICTED_VLA -# define Q_COMPILER_THREADSAFE_STATICS # if Q_CC_GNU >= 403 // GCC supports binary literals in C, C++98 and C++11 modes # define Q_COMPILER_BINARY_LITERALS @@ -980,7 +981,6 @@ # define Q_COMPILER_ATTRIBUTES // Almost working, see https://connect.microsoft.com/VisualStudio/feedback/details/2011648 //# define Q_COMPILER_CONSTEXPR -# define Q_COMPILER_THREADSAFE_STATICS # define Q_COMPILER_UNIFORM_INIT # endif # if _MSC_VER >= 1910 @@ -1048,13 +1048,6 @@ # define __USE_CONSTEXPR 1 # define __USE_NOEXCEPT 1 # endif -# if defined(Q_COMPILER_THREADSAFE_STATICS) && defined(Q_OS_MAC) -// Apple's low-level implementation of the C++ support library -// (libc++abi.dylib, shared between libstdc++ and libc++) has deadlocks. The -// C++11 standard requires the deadlocks to be removed, so this will eventually -// be fixed; for now, let's disable this. -# undef Q_COMPILER_THREADSAFE_STATICS -# endif #endif /* diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 674a2aea65..034ef274fa 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -55,17 +55,6 @@ enum GuardValues { }; } -#if !QT_CONFIG(thread) || defined(Q_COMPILER_THREADSAFE_STATICS) -// some compilers support thread-safe statics -// The IA-64 C++ ABI requires this, so we know that all GCC versions since 3.4 -// support it. C++11 also requires this behavior. -// Clang and Intel CC masquerade as GCC when compiling on Linux. -// -// Apple's libc++abi however uses a global lock for initializing local statics, -// which will block other threads also trying to initialize a local static -// until the constructor returns ... -// We better avoid these kind of problems by using our own locked implementation. - #if defined(Q_OS_UNIX) && defined(Q_CC_INTEL) // Work around Intel issue ID 6000058488: // local statics inside an inline function inside an anonymous namespace are global @@ -94,39 +83,7 @@ enum GuardValues { } holder; \ return &holder.value; \ } -#else -// We don't know if this compiler supports thread-safe global statics -// so use our own locked implementation -QT_END_NAMESPACE -#include -#include -QT_BEGIN_NAMESPACE - -#define Q_GLOBAL_STATIC_INTERNAL(ARGS) \ - Q_DECL_HIDDEN inline Type *innerFunction() \ - { \ - static Type *d; \ - static QBasicMutex mutex; \ - int x = guard.loadAcquire(); \ - if (Q_UNLIKELY(x >= QtGlobalStatic::Uninitialized)) { \ - const std::lock_guard locker(mutex); \ - if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) { \ - d = new Type ARGS; \ - static struct Cleanup { \ - Cleanup() = default; \ - ~Cleanup() { \ - delete d; \ - guard.storeRelaxed(QtGlobalStatic::Destroyed); \ - } \ - Q_DISABLE_COPY_MOVE(Cleanup) \ - } cleanup; \ - guard.storeRelease(QtGlobalStatic::Initialized); \ - } \ - } \ - return d; \ - } -#endif // this class must be POD, unless the compiler supports thread-safe statics template -- cgit v1.2.3