mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-27 23:47:03 +02:00
OH FUCK THE TIMINGS
This commit is contained in:
parent
94a34999a8
commit
46f799c9c8
1 changed files with 13 additions and 9 deletions
|
|
@ -183,7 +183,9 @@ bool Event::WaitFor(const std::chrono::nanoseconds time) {
|
||||||
_mm_monitorx(reinterpret_cast<u64*>(std::addressof(is_set)), 0, 0);
|
_mm_monitorx(reinterpret_cast<u64*>(std::addressof(is_set)), 0, 0);
|
||||||
if (!is_set.load()) {
|
if (!is_set.load()) {
|
||||||
// RDTSC may be fenced here due to atomic load
|
// RDTSC may be fenced here due to atomic load
|
||||||
u32 const cycles = std::min<u32>(std::numeric_limits<u32>::max(), s64(end) - s64(start));
|
auto const now = _rdtsc();
|
||||||
|
if (end > now) {
|
||||||
|
u32 const cycles = std::min<u32>(std::numeric_limits<u32>::max(), s64(end) - s64(now));
|
||||||
// See here: https://github.com/torvalds/linux/blob/948a64995aca6820abefd17f1a4258f5835c5ad9/arch/x86/lib/delay.c#L93
|
// See here: https://github.com/torvalds/linux/blob/948a64995aca6820abefd17f1a4258f5835c5ad9/arch/x86/lib/delay.c#L93
|
||||||
// MWAITX accepts a 32-bit input timer which determines the total number of cycles to wait for
|
// MWAITX accepts a 32-bit input timer which determines the total number of cycles to wait for
|
||||||
// NOT THE TOTAL ABSOLUTE TSC VALUE, it's just a delta
|
// NOT THE TOTAL ABSOLUTE TSC VALUE, it's just a delta
|
||||||
|
|
@ -192,6 +194,8 @@ bool Event::WaitFor(const std::chrono::nanoseconds time) {
|
||||||
_mm_mwaitx(1 << 1, 0u, cycles);
|
_mm_mwaitx(1 << 1, 0u, cycles);
|
||||||
if (!is_set.load())
|
if (!is_set.load())
|
||||||
return false;
|
return false;
|
||||||
|
} else
|
||||||
|
return false; //timeout
|
||||||
}
|
}
|
||||||
bool expected = true;
|
bool expected = true;
|
||||||
if (is_set.compare_exchange_weak(expected, false, std::memory_order_release))
|
if (is_set.compare_exchange_weak(expected, false, std::memory_order_release))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue