|
82 | 82 | #define COMPATIBILITY_OVERRIDE_H
|
83 | 83 |
|
84 | 84 | #include "../runtime/Private.h"
|
| 85 | +#include "swift/Runtime/CMakeConfig.h" |
85 | 86 | #include "swift/Runtime/Concurrency.h"
|
86 | 87 | #include "swift/Runtime/Metadata.h"
|
87 |
| -#include "swift/Runtime/Once.h" |
88 |
| -#include "swift/Runtime/CMakeConfig.h" |
| 88 | +#include <atomic> |
89 | 89 | #include <type_traits>
|
90 | 90 |
|
91 | 91 | namespace swift {
|
@@ -186,21 +186,41 @@ namespace swift {
|
186 | 186 | Override_##name getOverride_##name();
|
187 | 187 | #include "CompatibilityOverrideIncludePath.h"
|
188 | 188 |
|
| 189 | +#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \ |
| 190 | + SWIFT_NOINLINE \ |
| 191 | + static ret swift_##name##Slow(COMPATIBILITY_UNPAREN_WITH_COMMA(typedArgs) \ |
| 192 | + std::atomic<uintptr_t> &Override, \ |
| 193 | + uintptr_t fn, Original_##name defaultImpl) { \ |
| 194 | + constexpr uintptr_t DEFAULT_IMPL_SENTINEL = 0x1; \ |
| 195 | + if (SWIFT_UNLIKELY(fn == 0x0)) { \ |
| 196 | + fn = (uintptr_t)getOverride_##name(); \ |
| 197 | + if (fn == 0x0) { \ |
| 198 | + Override.store(DEFAULT_IMPL_SENTINEL, \ |
| 199 | + std::memory_order::memory_order_relaxed); \ |
| 200 | + return defaultImpl COMPATIBILITY_PAREN(namedArgs); \ |
| 201 | + } \ |
| 202 | + Override.store(fn, std::memory_order::memory_order_relaxed); \ |
| 203 | + } \ |
| 204 | + return ((Override_##name)fn)(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \ |
| 205 | + defaultImpl); \ |
| 206 | + } |
| 207 | +#include "CompatibilityOverrideIncludePath.h" |
| 208 | + |
189 | 209 | /// Used to define an override point. The override point #defines the appropriate
|
190 | 210 | /// OVERRIDE macro from CompatibilityOverride.def to this macro, then includes
|
191 | 211 | /// the file to generate the override points. The original implementation of the
|
192 | 212 | /// functionality must be available as swift_funcNameHereImpl.
|
193 | 213 | #define COMPATIBILITY_OVERRIDE(name, ret, attrs, ccAttrs, namespace, \
|
194 | 214 | typedArgs, namedArgs) \
|
195 | 215 | attrs ccAttrs ret namespace swift_##name COMPATIBILITY_PAREN(typedArgs) { \
|
196 |
| - static Override_##name Override; \ |
197 |
| - static swift_once_t Predicate; \ |
198 |
| - swift_once( \ |
199 |
| - &Predicate, [](void *) { Override = getOverride_##name(); }, nullptr); \ |
200 |
| - if (Override != nullptr) \ |
201 |
| - return Override(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \ |
202 |
| - swift_##name##Impl); \ |
203 |
| - return swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \ |
| 216 | + constexpr uintptr_t DEFAULT_IMPL_SENTINEL = 0x1; \ |
| 217 | + static std::atomic<uintptr_t> Override; \ |
| 218 | + uintptr_t fn = Override.load(std::memory_order::memory_order_relaxed); \ |
| 219 | + if (SWIFT_LIKELY(fn == DEFAULT_IMPL_SENTINEL)) { \ |
| 220 | + return swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \ |
| 221 | + } \ |
| 222 | + return ::swift_##name##Slow(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \ |
| 223 | + Override, fn, &swift_##name##Impl); \ |
204 | 224 | }
|
205 | 225 |
|
206 | 226 | #endif // #else SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT
|
|
0 commit comments