YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
queue.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/fault/detail/fiber/fiber_base.hpp
>
4
#include <
yaclib/fault/detail/fiber/scheduler.hpp
>
5
#include <
yaclib/fault/detail/fiber/system_clock.hpp
>
6
#include <
yaclib/fault/detail/wait_status.hpp
>
7
8
#include <vector>
9
10
namespace
yaclib::detail::fiber
{
11
12
struct
NoTimeoutTag
final
{};
13
14
class
FiberQueue
final
{
15
public
:
16
FiberQueue
()
noexcept
=
default
;
17
FiberQueue
(
FiberQueue
&&
other
) =
default
;
18
FiberQueue
&
operator
=(
FiberQueue
&&
other
)
noexcept
;
19
20
WaitStatus
Wait
(
NoTimeoutTag
);
21
22
template
<
typename
Rep
,
typename
Period
>
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
);
32
auto
*
scheduler
=
fault::Scheduler::GetScheduler
();
33
scheduler
->SleepPreemptive(
34
std::chrono::duration_cast<std::chrono::nanoseconds>(time_point.time_since_epoch()).count());
35
bool
res
=
queue_node
->Erase();
36
return
res
?
WaitStatus::Timeout
:
WaitStatus::Ready
;
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
yaclib::detail::fiber::BiList
Definition
bidirectional_intrusive_list.hpp:16
yaclib::detail::fiber::BiList::PushBack
void PushBack(Node *node) noexcept
Definition
bidirectional_intrusive_list.cpp:7
yaclib::detail::fiber::BiNodeWaitQueue
Definition
fiber_base.hpp:18
yaclib::detail::fiber::FiberBase
Definition
fiber_base.hpp:27
yaclib::detail::fiber::FiberQueue
Definition
queue.hpp:14
yaclib::detail::fiber::FiberQueue::Wait
WaitStatus Wait(const std::chrono::time_point< Clock, Duration > &time_point)
Definition
queue.hpp:28
yaclib::detail::fiber::FiberQueue::Empty
bool Empty() const noexcept
Definition
queue.cpp:39
yaclib::detail::fiber::FiberQueue::Wait
WaitStatus Wait(NoTimeoutTag)
Definition
queue.cpp:5
yaclib::detail::fiber::FiberQueue::FiberQueue
FiberQueue() noexcept=default
yaclib::detail::fiber::FiberQueue::NotifyAll
void NotifyAll()
Definition
queue.cpp:12
yaclib::detail::fiber::FiberQueue::NotifyOne
void NotifyOne()
Definition
queue.cpp:21
yaclib::fault::Scheduler::GetScheduler
static Scheduler * GetScheduler() noexcept
Definition
scheduler.cpp:30
yaclib::fault::Scheduler::Current
static detail::fiber::FiberBase * Current() noexcept
Definition
scheduler.cpp:48
fiber_base.hpp
yaclib::detail::fiber
Definition
atomic.hpp:7
yaclib::detail::WaitStatus
WaitStatus
Definition
wait_status.hpp:5
yaclib::detail::Ready
@ Ready
Definition
wait_status.hpp:7
yaclib::detail::Timeout
@ Timeout
Definition
wait_status.hpp:6
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
scheduler.hpp
yaclib::detail::fiber::NoTimeoutTag
Definition
queue.hpp:12
yaclib::detail::fiber::SystemClock::now
static time_point now()
Definition
system_clock.cpp:5
system_clock.hpp
wait_status.hpp
include
yaclib
fault
detail
fiber
queue.hpp
Generated by
1.9.8