YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
base_core.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <yaclib/config.hpp>
7#include <yaclib/log.hpp>
8#include <yaclib/util/ref.hpp>
9
10#if YACLIB_CORO != 0
11# include <yaclib/coro/coro.hpp>
12#endif
13
14#include <cstdint>
15#include <limits>
16#include <yaclib_std/atomic>
17
18namespace yaclib::detail {
19
20class BaseCore : public InlineCore {
21 public:
22 enum State : std::uintptr_t {
23 kEmpty = std::uintptr_t{0},
24 kResult = std::numeric_limits<std::uintptr_t>::max(),
25 };
26
27 void StoreCallback(InlineCore& callback) noexcept;
28
29 [[nodiscard]] bool Empty() const noexcept;
30
32
33 [[nodiscard]] bool Reset() noexcept;
34
35 // sometimes we know it will be last callback in cycle, so we want call it right now, instead of SetInline
37
39#if YACLIB_SYMMETRIC_TRANSFER != 0
40 using Transfer = std::conditional_t<SymmetricTransfer, yaclib_std::coroutine_handle<>, InlineCore*>;
41#else
43#endif
44
45 template <bool SymmetricTransfer>
47
48 template <bool SymmetricTransfer>
50
51#if YACLIB_CORO != 0 // Compiler inline this call in tests
52 [[nodiscard]] virtual yaclib_std::coroutine_handle<> Curr() noexcept { // LCOV_EXCL_LINE
53 YACLIB_PURE_VIRTUAL(); // LCOV_EXCL_LINE
54 return {}; // LCOV_EXCL_LINE
55 } // LCOV_EXCL_LINE
56#endif
57
58 protected:
59 explicit BaseCore(State callback) noexcept;
60
62
63 public:
65
66 void MoveExecutorTo(BaseCore& callback) noexcept;
67};
68
70 while (curr != nullptr) {
71 auto* next = curr->Here(*prev);
72 prev = curr;
73 curr = next;
74 }
75}
76
77} // namespace yaclib::detail
void StoreCallback(InlineCore &callback) noexcept
Definition base_core.cpp:8
Transfer< SymmetricTransfer > SetInline(InlineCore &callback) noexcept
Definition base_core.cpp:41
void MoveExecutorTo(BaseCore &callback) noexcept
Definition base_core.cpp:63
bool SetCallback(InlineCore &callback) noexcept
Definition base_core.cpp:19
yaclib_std::atomic_uintptr_t _callback
Definition base_core.hpp:61
bool Reset() noexcept
Definition base_core.cpp:28
bool Empty() const noexcept
Definition base_core.cpp:13
Transfer< SymmetricTransfer > SetResult() noexcept
Definition base_core.cpp:49
void CallInline(InlineCore &callback) noexcept
Definition base_core.cpp:33
#define YACLIB_PURE_VIRTUAL()
Definition log.hpp:86
YACLIB_INLINE void Loop(InlineCore *prev, InlineCore *curr) noexcept
Definition base_core.hpp:69
atomic< std::uintptr_t > atomic_uintptr_t
Definition atomic.hpp:85
IExecutor & MakeInline() noexcept
Get Inline executor singleton object.
Definition inline.cpp:34
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25