YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
scheduler.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <yaclib/log.hpp>
9
10#include <chrono>
11#include <map>
12
13namespace yaclib::detail::fiber {
14
15class FiberQueue;
16
17void SetRandomListPick(std::uint32_t k) noexcept;
18
19Node* PollRandomElementFromList(BiList& list);
20
21} // namespace yaclib::detail::fiber
22namespace yaclib::fault {
23
25 public:
26 static void SetTickLength(std::uint32_t tick) noexcept;
27
28 [[nodiscard]] bool IsRunning() const noexcept;
29
30 [[nodiscard]] std::uint64_t GetTimeNs() const noexcept;
31
33
34 static void RescheduleCurrent();
35
36 void Sleep(std::uint64_t ns);
37
38 void SleepPreemptive(std::uint64_t ns);
39
40 static detail::fiber::FiberBase* Current() noexcept;
41
43
44 static Scheduler* GetScheduler() noexcept;
45
46 static void Set(Scheduler* scheduler) noexcept;
47
48 static void Suspend();
49
50 private:
51 void AdvanceTime() noexcept;
52
53 void TickTime() noexcept;
54
55 detail::fiber::FiberBase* GetNext();
56
57 void RunLoop();
58
59 void WakeUpNeeded() noexcept;
60
61 std::uint32_t _random_list_pick = 10;
62
63 // TODO(myannyax) priority queue?
64 std::map<std::uint64_t, detail::fiber::BiList> _sleep_list;
65 // TODO(myannyax) priority queue?
67 std::uint64_t _time{0};
68 bool _running{false};
69};
70
71} // namespace yaclib::fault
void Schedule(detail::fiber::FiberBase *fiber)
Definition scheduler.cpp:38
static void SetTickLength(std::uint32_t tick) noexcept
static detail::fiber::FiberBase::Id GetId()
Definition scheduler.cpp:52
static void RescheduleCurrent()
std::uint64_t GetTimeNs() const noexcept
Definition scheduler.cpp:67
void SleepPreemptive(std::uint64_t ns)
static void Set(Scheduler *scheduler) noexcept
Definition scheduler.cpp:34
static Scheduler * GetScheduler() noexcept
Definition scheduler.cpp:30
static detail::fiber::FiberBase * Current() noexcept
Definition scheduler.cpp:48
void Sleep(std::uint64_t ns)
bool IsRunning() const noexcept
Definition scheduler.cpp:20
Node * PollRandomElementFromList(BiList &list)
void SetRandomListPick(std::uint32_t k) noexcept
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25