YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
make.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace yaclib {
7namespace detail {
8
9template <typename V, typename T>
10class ReadyCore : public UniqueCore<V, T> {
11 public:
13
14 template <typename... Args>
15 explicit ReadyCore(std::in_place_t, Args&&... args) {
16 // Body level try is required: in a constructor function try block the handler runs
17 // after the base is already destroyed and always rethrows at the end
18 try {
19 if constexpr (sizeof...(Args) == 0) {
20 this->Store(Unit{});
21 } else {
22 this->Store(std::forward<Args>(args)...);
23 }
24 } catch (...) {
25 this->Store(std::current_exception());
26 }
27 }
28
30 Loop(this, this->template SetResult<false>());
31 }
32
34 this->_result.~Result();
35 this->Store(StopTag{});
36 Call();
37 }
38
39 [[nodiscard]] InlineCore* Here(InlineCore& /*caller*/) noexcept final {
40 return this->template SetResult<false>();
41 }
42#if YACLIB_SYMMETRIC_TRANSFER != 0
43 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& /*caller*/) noexcept final {
44 return this->template SetResult<true>();
45 }
46#endif
47};
48
49} // namespace detail
50
51/**
52 * TODO(MBkkt) add description
53 */
54template <typename V = Unit, typename T = DefaultTrait, typename... Args>
55/*Task*/ auto MakeTask(Args&&... args) {
56 if constexpr (sizeof...(Args) == 0) {
57 using Value = std::conditional_t<std::is_same_v<V, Unit>, void, V>;
59 } else if constexpr (std::is_same_v<V, Unit>) {
60 using Head = std::decay_t<head_t<Args&&...>>;
61 using Value = std::conditional_t<std::is_same_v<Head, Unit>, void, Head>;
63 MakeUnique<detail::ReadyCore<Value, T>>(std::in_place, std::forward<Args>(args)...)}};
64 } else {
65 return Task{
66 detail::UniqueCorePtr<V, T>{MakeUnique<detail::ReadyCore<V, T>>(std::in_place, std::forward<Args>(args)...)}};
67 }
68}
69
70} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
Provides a mechanism to schedule the some async operations TODO(MBkkt) add description.
Definition task.hpp:25
void Drop() noexcept final
Definition make.hpp:33
InlineCore * Here(InlineCore &) noexcept final
Definition make.hpp:39
void Call() noexcept final
Definition make.hpp:29
typename UniqueCore< V, T >::Result Result
Definition make.hpp:12
ReadyCore(std::in_place_t, Args &&... args)
Definition make.hpp:15
void Store(Args &&... args)
typename ResultCore< V, T >::Result Result
YACLIB_INLINE void Loop(InlineCore *prev, InlineCore *curr) noexcept
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
typename detail::Head< Args... >::Type head_t
auto MakeTask(Args &&... args)
TODO(MBkkt) add description.
Definition make.hpp:55