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