YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
fiber.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <functional>
6
7namespace yaclib::detail::fiber {
8
9template <typename... Args>
10using FuncState = std::tuple<typename std::decay_t<Args>...>;
11
12template <typename... Args>
13class Fiber final : public FiberBase {
14 public:
15 // TODO(myannyax) add tests
16 Fiber(Args&&... args) : _func(std::forward<Args>(args)...) {
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
32
33 private:
34 template <typename Tuple, std::size_t... I>
36 std::invoke(std::move(std::get<I>(a))...);
37 }
38
39 FuncState<Args...> _func;
40};
41
42} // namespace yaclib::detail::fiber
void Setup(Allocation stack, Trampoline trampoline, void *arg)
static void Trampoline(void *arg) noexcept
Definition fiber.hpp:20
Fiber(Args &&... args)
Definition fiber.hpp:16
Allocation & GetAllocation() noexcept
Definition stack.hpp:29
void(*)(void *arg) Trampoline
std::tuple< typename std::decay_t< Args >... > FuncState
Definition fiber.hpp:10
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25