LeviLamina
Loading...
Searching...
No Matches
InterruptableSleep.h
1#pragma once
2
3#include <semaphore>
4
5namespace ll::thread {
7private:
8 std::binary_semaphore semaphore{0};
9
10public:
12 InterruptableSleep& operator=(InterruptableSleep const&) = delete;
13
14 constexpr InterruptableSleep() = default;
15
16 constexpr ~InterruptableSleep() = default;
17
18 template <class R, class P>
19 void sleepFor(std::chrono::duration<R, P> duration) {
20 (void)semaphore.try_acquire_for(duration);
21 }
22
23 template <class C, class D>
24 void sleepUntil(std::chrono::time_point<C, D> time) {
25 (void)semaphore.try_acquire_until(time);
26 }
27
28 void sleep() { semaphore.acquire(); }
29
30 void interrupt() { semaphore.release(); }
31};
32} // namespace ll::thread
Definition InterruptableSleep.h:6