Skip to content

Commit 8c5cbf5

Browse files
committed
rebase
1 parent 114c868 commit 8c5cbf5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

libcxx/include/__atomic/atomic_sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_all
114114
_APPLY(8)
115115
# elif defined(__FreeBSD__) && __SIZEOF_LONG__ == 8
116116
# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(8)
117+
# elif defined(_WIN32)
118+
# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(8)
117119
# else
118120
# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(sizeof(__cxx_contention_t))
119121
# endif // __linux__

libcxx/include/__atomic/contention_t.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ using __cxx_contention_t _LIBCPP_NODEBUG = int64_t;
2929
using __cxx_contention_t _LIBCPP_NODEBUG = int64_t;
3030
# elif defined(_AIX) && !defined(__64BIT__)
3131
using __cxx_contention_t _LIBCPP_NODEBUG = int32_t;
32+
#elif defined(_WIN32)
33+
using __cxx_contention_t _LIBCPP_NODEBUG = int64_t;
3234
# else
3335
using __cxx_contention_t _LIBCPP_NODEBUG = int64_t;
3436
# endif // __linux__

libcxx/src/atomic.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,30 @@ static void* win32_get_synch_api_function(const char* function_name) {
155155
return reinterpret_cast<void*>(GetProcAddress(module_handle, function_name));
156156
}
157157

158-
static void
159-
__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
158+
template <std::size_t _Size>
159+
static void __platform_wait_on_address(void const volatile* __ptr, void const* __val) {
160+
static_assert(_Size == 8, "Can only wait on 8 bytes value");
160161
// WaitOnAddress was added in Windows 8 (build 9200)
161162
static auto wait_on_address = reinterpret_cast<BOOL(WINAPI*)(volatile void*, PVOID, SIZE_T, DWORD)>(
162163
win32_get_synch_api_function("WaitOnAddress"));
163164
if (wait_on_address != nullptr) {
164-
wait_on_address(const_cast<__cxx_atomic_contention_t*>(__ptr), &__val, sizeof(__val), INFINITE);
165+
wait_on_address(const_cast<void*>(__ptr), &__val, _Size, INFINITE);
165166
} else {
166167
__libcpp_thread_poll_with_backoff(
167-
[=]() -> bool { return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__ptr, memory_order_relaxed), __val); },
168+
[=]() -> bool { return std::memcmp(const_cast<const void*>(__ptr), __val, _Size) != 0; },
168169
__libcpp_timed_backoff_policy());
169170
}
170171
}
171172

172-
static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
173+
template <std::size_t _Size>
174+
static void __platform_wake_by_address(void const volatile* __ptr, bool __notify_one) {
175+
static_assert(_Size == 8, "Can only wake up on 8 bytes value");
173176
if (__notify_one) {
174177
// WakeByAddressSingle was added in Windows 8 (build 9200)
175178
static auto wake_by_address_single =
176179
reinterpret_cast<void(WINAPI*)(PVOID)>(win32_get_synch_api_function("WakeByAddressSingle"));
177180
if (wake_by_address_single != nullptr) {
178-
wake_by_address_single(const_cast<__cxx_atomic_contention_t*>(__ptr));
181+
wake_by_address_single(const_cast<void*>(__ptr));
179182
} else {
180183
// The fallback implementation of waking does nothing, as the fallback wait implementation just does polling, so
181184
// there's nothing to do here.
@@ -185,7 +188,7 @@ static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const vo
185188
static auto wake_by_address_all =
186189
reinterpret_cast<void(WINAPI*)(PVOID)>(win32_get_synch_api_function("WakeByAddressAll"));
187190
if (wake_by_address_all != nullptr) {
188-
wake_by_address_all(const_cast<__cxx_atomic_contention_t*>(__ptr));
191+
wake_by_address_all(const_cast<void*>(__ptr));
189192
} else {
190193
// The fallback implementation of waking does nothing, as the fallback wait implementation just does polling, so
191194
// there's nothing to do here.

0 commit comments

Comments
 (0)