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 T>
13class SharedCore : public ResultCore<V, T> {
14 using ResultCore<V, T>::ResultCore;
15
16 public:
18
19 [[nodiscard]] InlineCore* Here(InlineCore& caller) noexcept override {
21 }
22
23#if YACLIB_SYMMETRIC_TRANSFER != 0
24 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& caller) noexcept override {
26 }
27#endif
28
30 // Higher refcount can be alive SharedFutures or transient refs of this core's
31 // callback dispatch, both forbid the move
32 // Both arms construct a prvalue: with glvalue arms of mixed value category
33 // the conditional would yield a const lvalue and the move arm would copy
34 auto result = (this->GetRef() == 1) ? Result{std::move(this->Get())} : Result{std::as_const(this->Get())};
35 this->DecRef();
36 return result;
37 }
38
40 return BaseCore::SetCallbackImpl<true>(callback);
41 }
42
43 // Users should be cautious calling SetInline on a SharedCore
44 // because the core's lifetime is managed by the SharedPromise and
45 // SharedFutures and they might all be gone by the time
46 // the callback is called
47 template <bool SymmetricTransfer>
49 return BaseCore::SetInlineImpl<SymmetricTransfer, true>(callback);
50 }
51
52 template <bool SymmetricTransfer>
54 return BaseCore::SetResultImpl<SymmetricTransfer, true>();
55 }
56};
57
58extern template class SharedCore<void, DefaultTrait>;
59
60template <typename V, typename T>
62
63} // 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.
Result & Get() noexcept
typename T::template Result< V > Result
Transfer< SymmetricTransfer > SetInline(InlineCore &callback) noexcept
Transfer< SymmetricTransfer > SetResult() noexcept
bool SetCallback(InlineCore &callback) noexcept
typename ResultCore< V, T >::Result Result
InlineCore * Here(InlineCore &caller) noexcept override
constexpr std::size_t kSharedRefNoFuture
constexpr std::size_t kSharedRefWithFuture
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25