coalesced event wait for with waitpkg/mwaitx/umonitorrrrrrr

This commit is contained in:
lizzie 2026-05-23 10:26:28 +00:00
parent bf175450d4
commit 60db19dca9
3 changed files with 70 additions and 26 deletions

View file

@ -15,6 +15,7 @@
#include <thread>
#include "common/common_types.h"
#include "common/polyfill_thread.h"
#include "common/x64/rdtsc.h"
namespace Common {
@ -34,15 +35,9 @@ public:
is_set = false;
}
bool WaitFor(const std::chrono::nanoseconds& time) {
std::unique_lock lk{mutex};
if (!condvar.wait_for(lk, time, [this] { return is_set.load(); }))
return false;
is_set = false;
return true;
}
bool WaitFor(const std::chrono::nanoseconds& time);
template <class Clock, class Duration>
template<class Clock, class Duration>
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
std::unique_lock lk{mutex};
if (!condvar.wait_until(lk, time, [this] { return is_set.load(); }))
@ -63,9 +58,9 @@ public:
}
private:
alignas(64) std::atomic<bool> is_set{false};
std::condition_variable condvar;
std::mutex mutex;
std::atomic_bool is_set{false};
};
class Barrier {