@@ -33,10 +33,21 @@ namespace lf::impl {
3333
3434// -------------------------------------------------------- //
3535
36+ /* *
37+ * @brief An awaiter to explicitly transfer execution to another worker.
38+ *
39+ * This is generated by `await_transform` when awaiting on a pointer to a `lf::context`.
40+ */
3641struct switch_awaitable : std::suspend_always {
3742
43+ /* *
44+ * @brief Shortcut if already on context.
45+ */
3846 auto await_ready () const noexcept { return tls::context () == dest; }
3947
48+ /* *
49+ * @brief Reschedule this coro onto `dest`.
50+ */
4051 auto await_suspend (std::coroutine_handle<>) noexcept -> std::coroutine_handle<> {
4152
4253 // Schedule this coro for execution on Dest.
@@ -71,14 +82,23 @@ struct switch_awaitable : std::suspend_always {
7182 return std::noop_coroutine ();
7283 }
7384
74- intrusive_list<submit_handle>::node self;
75- context *dest;
85+ intrusive_list<submit_handle>::node self; // /< The current coroutine's handle.
86+ context *dest; // /< Target context.
7687};
7788
7889// -------------------------------------------------------- //
7990
91+ /* *
92+ * @brief An awaiter that returns space allocated on the current fibre's stack.
93+ *
94+ * This never suspends the coroutine and is generated by `await_transform` when awaiting on a pointer to a
95+ * `lf::context`.
96+ */
8097template <typename T, std::size_t E>
8198struct alloc_awaitable : std::suspend_never, std::span<T, E> {
99+ /* *
100+ * @brief Return a handle to the memory.
101+ */
82102 [[nodiscard]] auto await_resume () const noexcept -> std::conditional_t<E == 1, T *, std::span<T, E>> {
83103 if constexpr (E == 1 ) {
84104 return this ->data ();
@@ -90,8 +110,16 @@ struct alloc_awaitable : std::suspend_never, std::span<T, E> {
90110
91111// -------------------------------------------------------- //
92112
113+ /* *
114+ * @brief An awaiter that suspends the current coroutine and transfers control to a child task.
115+ *
116+ * The parent task is made available for stealing. This is generated by `await_transform` when awaiting on an
117+ * `lf::impl::quasi_awaitable`.
118+ */
93119struct fork_awaitable : std::suspend_always {
94-
120+ /* *
121+ * @brief Sym-transfer to child, push parent to queue.
122+ */
95123 auto await_suspend (std::coroutine_handle<>) const noexcept -> std::coroutine_handle<> {
96124 LF_LOG (" Forking, push parent to context" );
97125 // Need a copy (on stack) in case *this is destructed after push.
@@ -100,22 +128,35 @@ struct fork_awaitable : std::suspend_always {
100128 return child;
101129 }
102130
103- frame *child;
104- frame *parent;
131+ frame *child; // /< The suspended child coroutine's frame.
132+ frame *parent; // /< The calling coroutine's frame.
105133};
106134
135+ /* *
136+ * @brief An awaiter that suspends the current coroutine and transfers control to a child task.
137+ *
138+ * The parent task is __not__ made available for stealing. This is generated by `await_transform` when
139+ * awaiting on an `lf::impl::quasi_awaitable`.
140+ */
107141struct call_awaitable : std::suspend_always {
108-
142+ /* *
143+ * @brief Sym-transfer to child.
144+ */
109145 auto await_suspend (std::coroutine_handle<>) const noexcept -> std::coroutine_handle<> {
110146 LF_LOG (" Calling" );
111147 return child->self ();
112148 }
113149
114- frame *child;
150+ frame *child; // /< The suspended child coroutine's frame.
115151};
116152
117153// -------------------------------------------------------------------------------- //
118154
155+ /* *
156+ * @brief An awaiter to synchronize execution of child tasks.
157+ *
158+ * This is generated by `await_transform` when awaiting on an `lf::impl::join_type`.
159+ */
119160struct join_awaitable {
120161 private:
121162 void take_stack_reset_frame () const noexcept {
@@ -128,6 +169,9 @@ struct join_awaitable {
128169 }
129170
130171 public:
172+ /* *
173+ * @brief Shortcut if children are ready.
174+ */
131175 auto await_ready () const noexcept -> bool {
132176 // If no steals then we are the only owner of the parent and we are ready to join.
133177 if (self->load_steals () == 0 ) {
@@ -154,6 +198,9 @@ struct join_awaitable {
154198 return false ;
155199 }
156200
201+ /* *
202+ * @brief Mark at join point then yield to scheduler or resume if children are done.
203+ */
157204 auto await_suspend (std::coroutine_handle<> task) const noexcept -> std::coroutine_handle<> {
158205 // Currently joins = k_u16_max - num_joined
159206 // We set joins = joins() - (k_u16_max - num_steals)
@@ -188,6 +235,9 @@ struct join_awaitable {
188235 return std::noop_coroutine ();
189236 }
190237
238+ /* *
239+ * @brief A noop in release.
240+ */
191241 void await_resume () const noexcept {
192242 LF_LOG (" join resumes" );
193243 // Check we have been reset.
@@ -196,7 +246,7 @@ struct join_awaitable {
196246 LF_ASSERT (self->stacklet () == tls::stack ()->top ());
197247 }
198248
199- frame *self;
249+ frame *self; // /< The frame of the awaiting coroutine.
200250};
201251
202252} // namespace lf::impl
0 commit comments