lizzie
4 days ago
committed by
crueter
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
1 changed files with
9 additions and
0 deletions
-
src/common/thread.cpp
|
|
@ -184,7 +184,11 @@ 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
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
auto const now = __rdtsc(); |
|
|
|
|
|
#else
|
|
|
auto const now = _rdtsc(); |
|
|
auto const now = _rdtsc(); |
|
|
|
|
|
#endif
|
|
|
if (end > now) { |
|
|
if (end > now) { |
|
|
u32 const cycles = std::min<u32>((std::numeric_limits<u32>::max)(), s64(end) - s64(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
|
|
|
@ -213,8 +217,13 @@ bool Event::WaitFor(const std::chrono::nanoseconds time) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
while (!is_set.load() && end > __rdtsc()) |
|
|
|
|
|
Common::Windows::SleepForOneTick(); |
|
|
|
|
|
#else
|
|
|
while (!is_set.load() && end > _rdtsc()) |
|
|
while (!is_set.load() && end > _rdtsc()) |
|
|
Common::Windows::SleepForOneTick(); |
|
|
Common::Windows::SleepForOneTick(); |
|
|
|
|
|
#endif
|
|
|
if (is_set.load()) |
|
|
if (is_set.load()) |
|
|
Reset(); |
|
|
Reset(); |
|
|
return true; |
|
|
return true; |
|
|
|