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
7
8#if YACLIB_CORO != 0
9# include <yaclib/coro/coro.hpp>
10#endif
11
12#include <limits>
13#include <yaclib_std/atomic>
14
15namespace yaclib::detail {
16
17class BaseCore : public InlineCore {
18 friend struct UniqueHandle;
19 friend struct SharedHandle;
20
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
28 auto callback = _callback.load(std::memory_order_acquire);
29 return callback == kEmpty;
30 }
31
32 template <bool Shared>
34 if (!callback._executor) {
35 YACLIB_ASSERT(_executor != nullptr);
37 }
38 }
39
40#if YACLIB_CORO != 0 // Compiler inline this call in tests
41 [[nodiscard]] virtual yaclib_std::coroutine_handle<> Curr() noexcept { // LCOV_EXCL_LINE
42 YACLIB_PURE_VIRTUAL(); // LCOV_EXCL_LINE
43 return {}; // LCOV_EXCL_LINE
44 } // LCOV_EXCL_LINE
45#endif
46
48
49 protected:
52
54 this->_callback.store(reinterpret_cast<std::uintptr_t>(&callback), std::memory_order_relaxed);
55 }
56
57 template <bool Shared>
58 [[nodiscard]] bool SetCallbackImpl(InlineCore& callback) noexcept;
59
60 [[nodiscard]] bool ResetImpl() noexcept;
61
64
67
68 yaclib_std::atomic_uintptr_t _callback;
69};
70
73 core.StoreCallbackImpl(callback);
74 }
75
77 return core.SetCallbackImpl<false>(callback);
78 }
79
80 bool Reset() noexcept {
81 return core.ResetImpl();
82 }
83
84 template <bool SymmetricTransfer>
86 return core.SetResultImpl<SymmetricTransfer, false>();
87 }
88
90};
91
94 return core.SetCallbackImpl<true>(callback);
95 }
96
98};
99
100} // namespace yaclib::detail
bool SetCallbackImpl(InlineCore &callback) noexcept
Definition base_core.cpp:6
void TransferExecutorTo(BaseCore &callback) noexcept
Definition base_core.hpp:33
bool ResetImpl() noexcept
Definition base_core.cpp:30
Transfer< SymmetricTransfer > SetInlineImpl(InlineCore &callback) noexcept
Definition base_core.cpp:37
yaclib_std::atomic_uintptr_t _callback
Definition base_core.hpp:68
Transfer< SymmetricTransfer > SetResultImpl() noexcept
Definition base_core.cpp:53
bool Empty() const noexcept
Definition base_core.hpp:27
BaseCore(State state) noexcept
Definition base_core.hpp:50
void StoreCallbackImpl(InlineCore &callback) noexcept
Definition base_core.hpp:53
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
#define YACLIB_PURE_VIRTUAL()
Definition log.hpp:86
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
bool SetCallback(InlineCore &callback) noexcept
Definition base_core.hpp:93
bool SetCallback(InlineCore &callback) noexcept
Definition base_core.hpp:76
void StoreCallback(InlineCore &callback) noexcept
Definition base_core.hpp:72
Transfer< SymmetricTransfer > SetResult() noexcept
Definition base_core.hpp:85