Skip to content

Commit 1db8885

Browse files
committed
Threading: repair the 32-bit Windows builds
This repairs the Windows x86 SDK build after swiftlang#59287. Use `intptr_t` rather than the explicitly sized integer as this is always guaranteed to be the size of the pointer width (irrespective of LP64/LP32 or LLP64/LLP32). Since this impacts only the once predicate, this shouldn't impact any assumptions around structure sizes.
1 parent 12486b1 commit 1db8885

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/swift/Threading/Impl/Win32.h

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

8989
// .. Once ...................................................................
9090

91-
typedef std::atomic<int64_t> once_t;
91+
typedef std::atomic<intptr_t> once_t;
9292

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

lib/Threading/Win32.cpp

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

6060
void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
6161
void *context) {
62-
std::int64_t expected = 0;
63-
if (predicate.compare_exchange_strong(expected, (std::int64_t)1,
62+
intptr_t expected = 0;
63+
if (predicate.compare_exchange_strong(expected, static_cast<intptr_t>(1),
6464
std::memory_order_relaxed,
6565
std::memory_order_relaxed)) {
6666
fn(context);
6767

68-
predicate.store((std::int64_t)-1, std::memory_order_release);
68+
predicate.store(static_cast<intptr_t>(-1), std::memory_order_release);
6969

7070
#if _WIN32_WINNT >= 0x0602
7171
// On Windows 8, use WakeByAddressAll() to wake waiters
@@ -84,7 +84,7 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
8484
#if _WIN32_WINNT >= 0x0602
8585
// On Windows 8, loop waiting on the address until it changes to -1
8686
while (expected >= 0) {
87-
WaitOnAddress(&predicate, &expected, 8, INFINITE);
87+
WaitOnAddress(&predicate, &expected, sizeof(expected), INFINITE);
8888
expected = predicate.load(std::memory_order_acquire);
8989
}
9090
#else

0 commit comments

Comments
 (0)