File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
include/swift/Threading/Impl Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,10 @@ inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {
135135
136136struct once_t {
137137 std::atomic<std::int32_t > flag;
138+ #if defined(__LP64__) || defined(_LP64)
139+ // On 32-bit Linux we can't have the lock, so we'll be less efficient
138140 linux::ulock_t lock;
141+ #endif
139142};
140143
141144void once_slow (once_t &predicate, void (*fn)(void *), void *context);
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ class MainThreadRememberer {
3636
3737MainThreadRememberer rememberer;
3838
39+ #if !defined(__LP64__) && !defined(_LP64)
40+ pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
41+ #endif
42+
3943#pragma clang diagnostic pop
4044
4145} // namespace
@@ -49,12 +53,21 @@ bool swift::threading_impl::thread_is_main() {
4953
5054void swift::threading_impl::once_slow (once_t &predicate, void (*fn)(void *),
5155 void *context) {
56+ // On 32-bit Linux we can't have per-once locks
57+ #if defined(__LP64__) || defined(_LP64)
5258 linux::ulock_lock (&predicate.lock );
59+ #else
60+ pthread_mutex_lock (&once_mutex);
61+ #endif
5362 if (predicate.flag .load (std::memory_order_acquire) == 0 ) {
5463 fn (context);
5564 predicate.flag .store (-1 , std::memory_order_release);
5665 }
66+ #if defined(__LP64__) || defined(_LP64)
5767 linux::ulock_unlock (&predicate.lock );
68+ #else
69+ pthread_mutex_unlock (&once_mutex);
70+ #endif
5871}
5972
6073llvm::Optional<swift::threading_impl::stack_bounds>
You can’t perform that action at this time.
0 commit comments