1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Revert "Atomics: use WaitOnAddress if available (Win8+)"

This reverts commit f0fd7e2e19.
This commit is contained in:
Nekotekina 2020-10-21 09:54:37 +03:00
parent 306593a0c5
commit 59d9e7ce98
2 changed files with 17 additions and 80 deletions

View File

@ -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__

View File

@ -214,13 +214,7 @@ namespace
};
}
#elif defined(_WIN32)
namespace
{
struct alignas(64) sema_handle
{
atomic_t<u64> 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<s64>(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<s64>(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)