diff --git a/Utilities/sync.h b/Utilities/sync.h index c002bfd98e..60ac01d9a1 100644 --- a/Utilities/sync.h +++ b/Utilities/sync.h @@ -28,14 +28,6 @@ DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOO DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout)); DYNAMIC_IMPORT("ntdll.dll", NtWaitForSingleObject, NTSTATUS(HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout)); DYNAMIC_IMPORT("ntdll.dll", NtDelayExecution, NTSTATUS(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval)); - -namespace wutex -{ - DYNAMIC_IMPORT("API-MS-Win-Core-Synch-l1-2-0.dll", WaitOnAddress, BOOL(volatile VOID* Address, PVOID CompareAddress, SIZE_T AddressSize, DWORD dwMilliseconds)); - DYNAMIC_IMPORT("API-MS-Win-Core-Synch-l1-2-0.dll", WakeByAddressSingle, BOOL(PVOID Address)); - DYNAMIC_IMPORT("API-MS-Win-Core-Synch-l1-2-0.dll", WakeByAddressAll, BOOL(PVOID Address)); -} - #endif #ifndef __linux__ diff --git a/rpcs3/util/atomic.cpp b/rpcs3/util/atomic.cpp index fc23ffd66f..b306831fb4 100644 --- a/rpcs3/util/atomic.cpp +++ b/rpcs3/util/atomic.cpp @@ -214,13 +214,7 @@ namespace }; } #elif defined(_WIN32) -namespace -{ - struct alignas(64) sema_handle - { - atomic_t sema; - }; -} +using sema_handle = std::uint16_t; #else namespace { @@ -566,41 +560,18 @@ void atomic_storage_futex::wait(const void* data, std::size_t size, u64 old_valu } } #elif defined(_WIN32) && !defined(USE_POSIX) - if (wutex::WaitOnAddress) + LARGE_INTEGER qw; + qw.QuadPart = -static_cast(timeout / 100); + + if (timeout % 100) { - if (s_sema_list[sema_id].sema.try_dec(0)) - { - fallback = true; - } - else - { - const DWORD time_ms = timeout + 1 ? INFINITE : (timeout > (UINT32_MAX - 1) * 1000'000 ? (UINT32_MAX - 1) : timeout / 1000'000); - - sema_handle _cmp{}; - - wutex::WaitOnAddress(&s_sema_list[sema_id].sema, &_cmp.sema, sizeof(_cmp.sema), time_ms); - - if (s_sema_list[sema_id].sema.try_dec(0)) - { - fallback = true; - } - } + // Round up to closest 100ns unit + qw.QuadPart -= 1; } - else + + if (!NtWaitForKeyedEvent(nullptr, &s_sema_list[sema_id], false, timeout + 1 ? &qw : nullptr)) { - LARGE_INTEGER qw; - qw.QuadPart = -static_cast(timeout / 100); - - if (timeout % 100) - { - // Round up to closest 100ns unit - qw.QuadPart -= 1; - } - - if (!NtWaitForKeyedEvent(nullptr, &s_sema_list[sema_id], false, timeout + 1 ? &qw : nullptr)) - { - fallback = true; - } + fallback = true; } #elif defined(USE_POSIX) struct timespec ts; @@ -700,21 +671,11 @@ void atomic_storage_futex::wait(const void* data, std::size_t size, u64 old_valu fallback = true; } #elif defined(_WIN32) && !defined(USE_POSIX) - if (wutex::WaitOnAddress) - { - if (s_sema_list[sema_id].sema.try_dec(0)) - { - fallback = true; - } - } - else - { - static LARGE_INTEGER instant{}; + static LARGE_INTEGER instant{}; - if (!NtWaitForKeyedEvent(nullptr, &s_sema_list[sema_id], false, &instant)) - { - fallback = true; - } + if (!NtWaitForKeyedEvent(nullptr, &s_sema_list[sema_id], false, &instant)) + { + fallback = true; } #elif defined(USE_POSIX) if (sem_trywait(&s_sema_list[sema_id]) == 0) @@ -811,15 +772,7 @@ void atomic_storage_futex::notify_one(const void* data) s_sema_list[sema_id].sema++; futex(&s_sema_list[sema_id].sema, FUTEX_WAKE_PRIVATE, 1); #elif defined(_WIN32) - if (wutex::WaitOnAddress) - { - s_sema_list[sema_id].sema++; - wutex::WakeByAddressSingle(&s_sema_list[sema_id].sema); - } - else - { - NtReleaseKeyedEvent(nullptr, &s_sema_list[sema_id], 1, nullptr); - } + NtReleaseKeyedEvent(nullptr, &s_sema_list[sema_id], 1, nullptr); #else dumb_sema& sema = *s_sema_list[sema_id]; @@ -877,17 +830,9 @@ void atomic_storage_futex::notify_all(const void* data) s_sema_list[sema_id].sema += count; futex(&s_sema_list[sema_id].sema, FUTEX_WAKE_PRIVATE, 0x7fff'ffff); #elif defined(_WIN32) - if (wutex::WaitOnAddress) + for (u32 i = 0; i < count; i++) { - s_sema_list[sema_id].sema += count; - wutex::WakeByAddressAll(&s_sema_list[sema_id].sema); - } - else - { - for (u32 i = 0; i < count; i++) - { - NtReleaseKeyedEvent(nullptr, &s_sema_list[sema_id], count, nullptr); - } + NtReleaseKeyedEvent(nullptr, &s_sema_list[sema_id], count, nullptr); } #else if (count)