Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/Threading/Impl/C11.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {

// .. Once ...................................................................

typedef std::atomic<std::int64_t> once_t;
typedef std::atomic<std::intptr_t> once_t;

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

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

once_slow(predicate, fn, context);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Threading/Impl/Pthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {

// .. Once ...................................................................

using once_t = std::atomic<std::int64_t>;
using once_t = std::atomic<std::intptr_t>;

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

Expand Down
13 changes: 6 additions & 7 deletions lib/Threading/C11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ bool swift::threading_impl::thread_is_main() {

void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
void *context) {
std::int64_t zero = 0;
if (std::atomic_compare_exchange_strong_explicit(&predicate, &zero, 1,
std::memory_order_relaxed,
std::memory_order_relaxed)) {
std::intptr_t zero = 0;
if (predicate.compare_exchange_strong(zero, (std::intptr_t)1,
std::memory_order_relaxed,
std::memory_order_relaxed)) {
fn(context);

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

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

helper.once_lock();
while (std::atomic_load_explicit(&predicate, std::memory_order_acquire) >=
0) {
while (predicate.load(std::memory_order_acquire) >= (std::intptr_t)0) {
helper.once_wait();
}
helper.once_unlock();
Expand Down
8 changes: 4 additions & 4 deletions lib/Threading/Pthreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ bool swift::threading_impl::thread_is_main() {

void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
void *context) {
std::int64_t zero = 0;
if (predicate.compare_exchange_strong(zero, (std::int64_t)1,
std::intptr_t zero = 0;
if (predicate.compare_exchange_strong(zero, (std::intptr_t)1,
std::memory_order_relaxed,
std::memory_order_relaxed)) {
fn(context);

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

pthread_mutex_lock(&onceMutex);
pthread_mutex_unlock(&onceMutex);
Expand All @@ -70,7 +70,7 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
}

pthread_mutex_lock(&onceMutex);
while (predicate.load(std::memory_order_acquire) >= (std::int64_t)0) {
while (predicate.load(std::memory_order_acquire) >= (std::intptr_t)0) {
pthread_cond_wait(&onceCond, &onceMutex);
}
pthread_mutex_unlock(&onceMutex);
Expand Down