YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
queue.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <vector>
9
10namespace yaclib::detail::fiber {
11
13
15 public:
19
21
23 WaitStatus Wait(const std::chrono::duration<Rep, Period>& duration) {
24 return Wait(duration + SystemClock::now());
25 }
26
27 template <typename Clock, typename Duration>
28 WaitStatus Wait(const std::chrono::time_point<Clock, Duration>& time_point) {
29 auto* fiber = fault::Scheduler::Current();
30 auto* queue_node = static_cast<BiNodeWaitQueue*>(fiber);
31 _queue.PushBack(queue_node);
33 scheduler->SleepPreemptive(
34 std::chrono::duration_cast<std::chrono::nanoseconds>(time_point.time_since_epoch()).count());
35 bool res = queue_node->Erase();
37 }
38
39 void NotifyAll();
40
41 void NotifyOne();
42
43 [[nodiscard]] bool Empty() const noexcept;
44
45 ~FiberQueue();
46
47 private:
48 static void ScheduleAndRemove(FiberBase* node);
49
50 BiList _queue;
51};
52
53} // namespace yaclib::detail::fiber
WaitStatus Wait(const std::chrono::time_point< Clock, Duration > &time_point)
Definition queue.hpp:28
bool Empty() const noexcept
Definition queue.cpp:39
WaitStatus Wait(NoTimeoutTag)
Definition queue.cpp:5
static Scheduler * GetScheduler() noexcept
Definition scheduler.cpp:30
static detail::fiber::FiberBase * Current() noexcept
Definition scheduler.cpp:48
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25