Skip to content

Commit 672c106

Browse files
authored
Merge pull request #59586 from al45tair/eng/PR-95523756
[Threading] Support 32-bit platforms for C11 threads and pthreads.
2 parents 3ae75e3 + 141f00b commit 672c106

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

include/swift/Threading/Impl/C11.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {
148148

149149
// .. Once ...................................................................
150150

151-
typedef std::atomic<std::int64_t> once_t;
151+
typedef std::atomic<std::intptr_t> once_t;
152152

153153
void once_slow(once_t &predicate, void (*fn)(void *), void *context);
154154

155155
inline void once_impl(once_t &predicate, void (*fn)(void *), void *context) {
156156
// Sadly we can't use call_once() for this (no context)
157-
if (std::atomic_load_explicit(&predicate, std::memory_order_acquire) < 0)
157+
if (predicate.load(std::memory_order_acquire) < 0)
158158
return;
159159

160160
once_slow(predicate, fn, context);

include/swift/Threading/Impl/Pthreads.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {
131131

132132
// .. Once ...................................................................
133133

134-
using once_t = std::atomic<std::int64_t>;
134+
using once_t = std::atomic<std::intptr_t>;
135135

136136
void once_slow(once_t &predicate, void (*fn)(void *), void *context);
137137

lib/Threading/C11.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ bool swift::threading_impl::thread_is_main() {
6464

6565
void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
6666
void *context) {
67-
std::int64_t zero = 0;
68-
if (std::atomic_compare_exchange_strong_explicit(&predicate, &zero, 1,
69-
std::memory_order_relaxed,
70-
std::memory_order_relaxed)) {
67+
std::intptr_t zero = 0;
68+
if (predicate.compare_exchange_strong(zero, (std::intptr_t)1,
69+
std::memory_order_relaxed,
70+
std::memory_order_relaxed)) {
7171
fn(context);
7272

73-
std::atomic_store_explicit(&predicate, -1, std::memory_order_release);
73+
predicate.store((std::intptr_t)-1, std::memory_order_release);
7474

7575
helper.once_lock();
7676
helper.once_unlock();
@@ -79,8 +79,7 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
7979
}
8080

8181
helper.once_lock();
82-
while (std::atomic_load_explicit(&predicate, std::memory_order_acquire) >=
83-
0) {
82+
while (predicate.load(std::memory_order_acquire) >= (std::intptr_t)0) {
8483
helper.once_wait();
8584
}
8685
helper.once_unlock();

lib/Threading/Pthreads.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ bool swift::threading_impl::thread_is_main() {
5555

5656
void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
5757
void *context) {
58-
std::int64_t zero = 0;
59-
if (predicate.compare_exchange_strong(zero, (std::int64_t)1,
58+
std::intptr_t zero = 0;
59+
if (predicate.compare_exchange_strong(zero, (std::intptr_t)1,
6060
std::memory_order_relaxed,
6161
std::memory_order_relaxed)) {
6262
fn(context);
6363

64-
predicate.store((std::int64_t)-1, std::memory_order_release);
64+
predicate.store((std::intptr_t)-1, std::memory_order_release);
6565

6666
pthread_mutex_lock(&onceMutex);
6767
pthread_mutex_unlock(&onceMutex);
@@ -70,7 +70,7 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
7070
}
7171

7272
pthread_mutex_lock(&onceMutex);
73-
while (predicate.load(std::memory_order_acquire) >= (std::int64_t)0) {
73+
while (predicate.load(std::memory_order_acquire) >= (std::intptr_t)0) {
7474
pthread_cond_wait(&onceCond, &onceMutex);
7575
}
7676
pthread_mutex_unlock(&onceMutex);

0 commit comments

Comments
 (0)