YOrch 1.0.0
Loading...
Searching...
No Matches
serial_dfs.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "../../result.hpp"
6#include "node_entry.hpp"
7
8namespace yorch::detail {
9
10template <typename Plan, std::size_t I>
13 bool armed = false;
14
17
21 if (armed) {
23 }
24 }
25
26 constexpr void arm() noexcept {
27 armed = true;
28 }
29};
30
31template <std::size_t I, std::size_t Ord = 0, typename Plan, typename Slots>
33 Plan& plan,
34 Slots& slots,
36
37template <std::size_t I, std::size_t Ord = 0, typename Plan, typename Slots, typename Ctx>
39 Plan& plan,
40 Slots& slots,
42 Ctx& ctx);
43
44template <std::size_t I, typename Plan, typename Slots>
46 Plan& plan,
47 Slots& slots,
49 const auto entered = enter_node<I>(plan, slots, fanout);
50
51 if (!entered.step.ok()) {
52 return entered.step;
53 }
54
56 if (entered.payload_live) {
57 guard.arm();
58 }
59
60 return run_children<I>(plan, slots, fanout);
61}
62
63template <std::size_t I, typename Plan, typename Slots, typename Ctx>
65 Plan& plan,
66 Slots& slots,
68 Ctx& ctx) {
69 const auto entered = enter_node<I>(plan, slots, fanout, ctx);
70
71 if (!entered.step.ok()) {
72 return entered.step;
73 }
74
76 if (entered.payload_live) {
77 guard.arm();
78 }
79
80 return run_children<I>(plan, slots, fanout, ctx);
81}
82
83template <std::size_t I, std::size_t Ord, typename Plan, typename Slots>
85 Plan& plan,
86 Slots& slots,
88 static_cast<void>(plan);
89 static_cast<void>(slots);
90
92 if constexpr (Ord == 0) {
93 fanout.template prepare_fanout_staging<I>(slots);
94 guard.arm();
95 }
96
97 if constexpr (Ord == Plan::template child_count<I>) {
98 return step_result::success();
99 } else {
100 constexpr auto child = Plan::template child_index<I, Ord>;
101
102 const auto child_step = run_node<child>(plan, slots, fanout);
103
105 return run_children<I, Ord + 1>(plan, slots, fanout);
106 }
107
108 if (!child_step.ok()) {
109 return child_step;
110 }
111
112 return run_children<I, Ord + 1>(plan, slots, fanout);
113 }
114}
115
116template <std::size_t I, std::size_t Ord, typename Plan, typename Slots, typename Ctx>
118 Plan& plan,
119 Slots& slots,
121 Ctx& ctx) {
122 static_cast<void>(plan);
123 static_cast<void>(slots);
124 static_cast<void>(ctx);
125
127 if constexpr (Ord == 0) {
128 fanout.template prepare_fanout_staging<I>(slots);
129 guard.arm();
130 }
131
132 if constexpr (Ord == Plan::template child_count<I>) {
133 return step_result::success();
134 } else {
135 constexpr auto child = Plan::template child_index<I, Ord>;
136
137 const auto child_step = run_node<child>(plan, slots, fanout, ctx);
138
140 return run_children<I, Ord + 1>(plan, slots, fanout, ctx);
141 }
142
143 if (!child_step.ok()) {
144 return child_step;
145 }
146
147 return run_children<I, Ord + 1>(plan, slots, fanout, ctx);
148 }
149}
150
151} // namespace yorch::detail
constexpr step_result run_children(Plan &plan, Slots &slots, plan_fanout_state< Plan > &fanout)
constexpr step_result run_node(Plan &plan, Slots &slots, plan_fanout_state< Plan > &fanout)
constexpr bool is_adapter_descriptor_v
Definition adapters.hpp:63
node_fanout_guard & operator=(const node_fanout_guard &)=default
constexpr void arm() noexcept
plan_fanout_state< Plan > * fanout
constexpr node_fanout_guard(plan_fanout_state< Plan > *in_fanout) noexcept
node_fanout_guard(const node_fanout_guard &)=default
constexpr void arm() noexcept
Definition result.hpp:105
Represents the basic outcome of a task step.
Definition result.hpp:42
static constexpr step_result success() noexcept
Creates a successful result.
Definition result.hpp:46