YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
fiber.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/fault/detail/fiber/fiber_base.hpp
>
4
5
#include <functional>
6
7
namespace
yaclib::detail::fiber
{
8
9
template
<
typename
...
Args
>
10
using
FuncState
= std::tuple<typename std::decay_t<Args>...>;
11
12
template
<
typename
...
Args
>
13
class
Fiber
final
:
public
FiberBase
{
14
public
:
15
// TODO(myannyax) add tests
16
Fiber
(
Args
&&...
args
) : _func(std::
forward
<
Args
>(
args
)...) {
17
_context
.
Setup
(
_stack
.
GetAllocation
(),
Trampoline
,
this
);
18
}
19
20
static
void
Trampoline
(
void
*
arg
)
noexcept
{
21
auto
& fiber = *
reinterpret_cast<
Fiber
*
>
(
arg
);
22
fiber.
Start
();
23
try
{
24
Helper
(fiber._func, std::index_sequence_for<
FuncState<Args...>
>{});
25
}
catch
(...) {
26
fiber._exception = std::current_exception();
27
}
28
fiber.Exit();
29
}
30
31
~Fiber
()
final
=
default
;
32
33
private
:
34
template
<
typename
Tuple
, std::
size_t
...
I
>
35
static
auto
Helper
(
Tuple
&
a
, std::
index_sequence
<
I
...>) {
36
std::invoke(std::move(std::get<I>(
a
))...);
37
}
38
39
FuncState
<
Args
...> _func;
40
};
41
42
}
// namespace yaclib::detail::fiber
yaclib::detail::Helper
Definition
helper.hpp:11
yaclib::detail::fiber::ExecutionContext::Setup
void Setup(Allocation stack, Trampoline trampoline, void *arg)
Definition
execution_context.cpp:7
yaclib::detail::fiber::FiberBase
Definition
fiber_base.hpp:27
yaclib::detail::fiber::FiberBase::Start
void Start()
Definition
fiber_base.cpp:38
yaclib::detail::fiber::FiberBase::_context
ExecutionContext _context
Definition
fiber_base.hpp:61
yaclib::detail::fiber::FiberBase::_stack
Stack _stack
Definition
fiber_base.hpp:62
yaclib::detail::fiber::Fiber
Definition
fiber.hpp:13
yaclib::detail::fiber::Fiber::Trampoline
static void Trampoline(void *arg) noexcept
Definition
fiber.hpp:20
yaclib::detail::fiber::Fiber::~Fiber
~Fiber() final=default
yaclib::detail::fiber::Fiber::Fiber
Fiber(Args &&... args)
Definition
fiber.hpp:16
yaclib::detail::fiber::Stack::GetAllocation
Allocation & GetAllocation() noexcept
Definition
stack.hpp:29
fiber_base.hpp
yaclib::detail::fiber
Definition
atomic.hpp:7
yaclib::detail::fiber::Trampoline
void(*)(void *arg) Trampoline
Definition
execution_context.hpp:14
yaclib::detail::fiber::FuncState
std::tuple< typename std::decay_t< Args >... > FuncState
Definition
fiber.hpp:10
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
include
yaclib
fault
detail
fiber
fiber.hpp
Generated by
1.9.8