|
18 | 18 | SWIFT_RUNTIME_STDLIB_INTERNAL |
19 | 19 | void * _Nonnull _swift_stdlib_threadLocalStorageGet(void); |
20 | 20 |
|
| 21 | +SWIFT_RUNTIME_STDLIB_INTERNAL |
| 22 | +void * _Nullable _swift_getExclusivityTLSImpl(); |
| 23 | + |
| 24 | +SWIFT_RUNTIME_STDLIB_INTERNAL |
| 25 | +void _swift_setExclusivityTLSImpl(void * _Nullable newValue); |
| 26 | + |
| 27 | +#if defined(__APPLE__) && __arm64__ |
| 28 | + |
| 29 | +// Use a fast path on Apple ARM64, where we have a dedicated TLS key and fast |
| 30 | +// access to read/write it. |
| 31 | + |
| 32 | +#ifndef __PTK_FRAMEWORK_SWIFT_KEY7 |
| 33 | +# define __PTK_FRAMEWORK_SWIFT_KEY7 107 |
| 34 | +#endif |
| 35 | + |
| 36 | +#define SWIFT_RUNTIME_EXCLUSIVITY_KEY __PTK_FRAMEWORK_SWIFT_KEY7 |
| 37 | + |
| 38 | +static inline void * _Nullable * _Nonnull _swift_getExclusivityTLSPointer() { |
| 39 | + unsigned long tsd; |
| 40 | + __asm__ ("mrs %0, TPIDRRO_EL0" : "=r" (tsd)); |
| 41 | + void **base = (void **)tsd; |
| 42 | + return &base[SWIFT_RUNTIME_EXCLUSIVITY_KEY]; |
| 43 | +} |
| 44 | + |
| 45 | +static inline void * _Nullable _swift_getExclusivityTLS() { |
| 46 | + return *_swift_getExclusivityTLSPointer(); |
| 47 | +} |
| 48 | + |
| 49 | +static inline void _swift_setExclusivityTLS(void * _Nullable newValue) { |
| 50 | + *_swift_getExclusivityTLSPointer() = newValue; |
| 51 | +} |
| 52 | + |
| 53 | +#else |
| 54 | + |
| 55 | +static inline void * _Nullable _swift_getExclusivityTLS() { |
| 56 | + return _swift_getExclusivityTLSImpl(); |
| 57 | +} |
| 58 | + |
| 59 | +static inline void _swift_setExclusivityTLS(void * _Nullable newValue) { |
| 60 | + _swift_setExclusivityTLSImpl(newValue); |
| 61 | +} |
| 62 | + |
| 63 | +#endif |
| 64 | + |
21 | 65 | #endif // SWIFT_STDLIB_SHIMS_THREADLOCALSTORAGE_H |
0 commit comments