YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
this_thread.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib_std/chrono>
4
5#if YACLIB_FAULT_THIS_THREAD == 2
7
9
10template <typename Clock, typename Duration>
11inline void sleep_until(const std::chrono::time_point<Clock, Duration>& sleep_time) {
12 std::uint64_t timeout = std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_time.time_since_epoch()).count();
14}
15
16template <typename Rep, typename Period>
17void sleep_for(const std::chrono::duration<Rep, Period>& sleep_duration) {
18 sleep_until(yaclib_std::chrono::steady_clock::now() + sleep_duration);
19}
20
21inline constexpr auto* yield = &yaclib::fault::Scheduler::RescheduleCurrent;
22
23inline constexpr auto* get_id = &yaclib::fault::Scheduler::GetId;
24
25} // namespace yaclib_std::this_thread
26// #elif YACLIB_FAULT_THIS_THREAD == 1 // TODO(myannyax) Maybe implement
27// # error "YACLIB_FAULT=THREAD not implemented yet"
28#else
29# include <thread>
30
32
33using std::this_thread::sleep_for;
34
35using std::this_thread::sleep_until;
36
37using std::this_thread::yield;
38
39using std::this_thread::get_id;
40
41} // namespace yaclib_std::this_thread
42#endif
static detail::fiber::FiberBase::Id GetId()
Definition scheduler.cpp:52
static void RescheduleCurrent()
static Scheduler * GetScheduler() noexcept
Definition scheduler.cpp:30
void Sleep(std::uint64_t ns)