YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
queue.cpp
Go to the documentation of this file.
2
3namespace yaclib::detail::fiber {
4
11
13 auto all = std::move(_queue);
14 _queue = BiList();
15 while (!all.Empty()) {
16 auto* fiber = static_cast<FiberBase*>(static_cast<BiNodeWaitQueue*>(all.PopBack()));
17 ScheduleAndRemove(fiber);
18 }
19}
20
22 if (_queue.Empty()) {
23 return;
24 }
25 auto* fiber = static_cast<FiberBase*>(static_cast<BiNodeWaitQueue*>(PollRandomElementFromList(_queue)));
26 ScheduleAndRemove(fiber);
27}
28
30 YACLIB_DEBUG(!_queue.Empty(), "queue must be empty on destruction - potentially deadlock");
31}
32
34 _queue = std::move(other._queue);
35 other._queue = BiList();
36 return *this;
37}
38
40 return _queue.Empty();
41}
42
43void FiberQueue::ScheduleAndRemove(FiberBase* node) {
44 if (node->GetState() != Waiting) {
45 static_cast<BiNodeScheduler*>(node)->Erase();
47 }
48}
49
50} // namespace yaclib::detail::fiber
bool Empty() const noexcept
Definition queue.cpp:39
WaitStatus Wait(NoTimeoutTag)
Definition queue.cpp:5
FiberQueue & operator=(FiberQueue &&other) noexcept
Definition queue.cpp:33
void Schedule(detail::fiber::FiberBase *fiber)
Definition scheduler.cpp:38
static Scheduler * GetScheduler() noexcept
Definition scheduler.cpp:30
static detail::fiber::FiberBase * Current() noexcept
Definition scheduler.cpp:48
#define YACLIB_DEBUG(cond, message)
Definition log.hpp:84
Node * PollRandomElementFromList(BiList &list)
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25