YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_core.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace yaclib::detail {
6
7// 3 refs for the promise (1 for the promise itself and 2 for the last callback)
8// 1 ref for the future
9inline constexpr std::size_t kSharedRefWithFuture = 4;
10inline constexpr std::size_t kSharedRefNoFuture = 3;
11
12template <typename V, typename E>
13class SharedCore : public ResultCore<V, E> {
14 using ResultCore<V, E>::ResultCore;
15
16 public:
17 [[nodiscard]] InlineCore* Here(InlineCore& caller) noexcept override {
19 }
20
21#if YACLIB_SYMMETRIC_TRANSFER != 0
22 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& caller) noexcept override {
24 }
25#endif
26
28 auto result = (this->GetRef() == 1) ? std::move(this->Get()) : std::as_const(this->Get());
29 this->DecRef();
30 return result;
31 }
32
34 return BaseCore::SetCallbackImpl<true>(callback);
35 }
36
37 // Users should be cautious calling SetInline on a SharedCore
38 // because the core's lifetime is managed by the SharedPromise and
39 // SharedFutures and they might all be gone by the time
40 // the callback is called
41 template <bool SymmetricTransfer>
43 return BaseCore::SetInlineImpl<SymmetricTransfer, true>(callback);
44 }
45
46 template <bool SymmetricTransfer>
48 return BaseCore::SetResultImpl<SymmetricTransfer, true>();
49 }
50};
51
52extern template class SharedCore<void, StopError>;
53
54template <typename V, typename E>
56
57} // namespace yaclib::detail
virtual void DecRef() noexcept
Decrements reference counter.
Definition ref.hpp:23
virtual std::size_t GetRef() noexcept
Definition ref.hpp:29
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
Definition result.hpp:90
Result< V, E > & Get() noexcept
Result< V, E > Retire() final
InlineCore * Here(InlineCore &caller) noexcept override
Transfer< SymmetricTransfer > SetResult() noexcept
bool SetCallback(InlineCore &callback) noexcept
Transfer< SymmetricTransfer > SetInline(InlineCore &callback) noexcept
constexpr std::size_t kSharedRefNoFuture
constexpr std::size_t kSharedRefWithFuture
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25