Skip to content

Commit 24be7ec

Browse files
author
Greg Parker
authored
Merge pull request #12515 from gparker42/GrP-PR-B214D8DD-7BCA-4F55-BB7E-3A86D30CA9BD
[runtime] Don't use C++ thread_local on two old Apple simulators.
2 parents 34e602b + 1a0e3e7 commit 24be7ec

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

stdlib/public/runtime/Exclusivity.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@
2727
// If we're using Clang, and Clang claims not to support thread_local,
2828
// it must be because we're on a platform that doesn't support it.
2929
// Use pthreads.
30-
#if __clang__ && !__has_feature(cxx_thread_local)
31-
#define SWIFT_EXCLUSIVITY_USE_THREADLOCAL 0
32-
#define SWIFT_EXCLUSIVITY_USE_PTHREAD_SPECIFIC 1
30+
// Workaround: has_feature(cxx_thread_local) is wrong on two old Apple
31+
// simulators. clang thinks thread_local works there, but it doesn't.
32+
#if TARGET_OS_SIMULATOR && !TARGET_RT_64_BIT && \
33+
((TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \
34+
(TARGET_OS_WATCH && __WATCHOS_OS_VERSION_MIN_REQUIRED__ < 30000))
35+
// 32-bit iOS 9 simulator or 32-bit watchOS 2 simulator - use pthreads
36+
# define SWIFT_EXCLUSIVITY_USE_THREADLOCAL 0
37+
# define SWIFT_EXCLUSIVITY_USE_PTHREAD_SPECIFIC 1
38+
#elif __clang__ && !__has_feature(cxx_thread_local)
39+
// clang without thread_local support - use pthreads
40+
# define SWIFT_EXCLUSIVITY_USE_THREADLOCAL 0
41+
# define SWIFT_EXCLUSIVITY_USE_PTHREAD_SPECIFIC 1
3342
#else
34-
#define SWIFT_EXCLUSIVITY_USE_THREADLOCAL 1
35-
#define SWIFT_EXCLUSIVITY_USE_PTHREAD_SPECIFIC 0
43+
// Use thread_local
44+
# define SWIFT_EXCLUSIVITY_USE_THREADLOCAL 1
45+
# define SWIFT_EXCLUSIVITY_USE_PTHREAD_SPECIFIC 0
3646
#endif
3747

3848
#endif

0 commit comments

Comments
 (0)