17class ServerTickSyncSleepBase {
19 std::unique_ptr<Impl> impl;
22 LLAPI std::unique_lock<std::mutex> lock();
24 LLAPI
void sleepImpl(std::unique_lock<std::mutex>&);
25 LLAPI
void interruptImpl();
27 virtual void check() = 0;
30 ServerTickSyncSleepBase(ServerTickSyncSleepBase&&) =
delete;
31 ServerTickSyncSleepBase(ServerTickSyncSleepBase
const&) =
delete;
32 ServerTickSyncSleepBase& operator=(ServerTickSyncSleepBase&&) =
delete;
33 ServerTickSyncSleepBase& operator=(ServerTickSyncSleepBase
const&) =
delete;
35 LLAPI ServerTickSyncSleepBase();
36 LLAPI
virtual ~ServerTickSyncSleepBase();
40class ServerTickSyncSleep :
public ServerTickSyncSleepBase {
41 void check()
override {
42 if (!timepoint)
return;
43 if (Clock::now() >= *timepoint) {
49 using clock_type = Clock;
51 std::optional<typename Clock::time_point> timepoint;
53 ServerTickSyncSleep() =
default;
54 virtual ~ServerTickSyncSleep() =
default;
56 void sleepFor(Clock::duration duration) {
57 std::unique_lock l{lock()};
58 timepoint = Clock::now() + duration;
62 void sleepUntil(Clock::time_point time) {
63 std::unique_lock l{lock()};
69 std::unique_lock l{lock()};
70 timepoint = std::nullopt;
75 std::unique_lock l{lock()};
76 timepoint = std::nullopt;