100.00% Lines (4/4) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2026 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2026 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2026 Steve Gerbino 3   // Copyright (c) 2026 Steve Gerbino
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/corosio 8   // Official repository: https://github.com/cppalliance/corosio
9   // 9   //
10   10  
11   #ifndef BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP 11   #ifndef BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP
12   #define BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP 12   #define BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP
13   13  
14   #include <boost/corosio/io_context.hpp> 14   #include <boost/corosio/io_context.hpp>
15   #include <boost/capy/continuation.hpp> 15   #include <boost/capy/continuation.hpp>
16   #include <boost/capy/ex/executor_ref.hpp> 16   #include <boost/capy/ex/executor_ref.hpp>
17   #include <boost/capy/detail/type_id.hpp> 17   #include <boost/capy/detail/type_id.hpp>
18   #include <coroutine> 18   #include <coroutine>
19   19  
20   namespace boost::corosio::detail { 20   namespace boost::corosio::detail {
21   21  
22   /** Returns a handle for symmetric transfer on I/O completion. 22   /** Returns a handle for symmetric transfer on I/O completion.
23   23  
24   Returns `c.h` when the executor's context is running on the 24   Returns `c.h` when the executor's context is running on the
25   calling thread, so the awaiter resumes by symmetric transfer. 25   calling thread, so the awaiter resumes by symmetric transfer.
26   Otherwise the executor queues `c` and `noop_coroutine()` is 26   Otherwise the executor queues `c` and `noop_coroutine()` is
27   returned. An `io_context` executor is dispatched without type 27   returned. An `io_context` executor is dispatched without type
28   erasure. 28   erasure.
29   29  
30   Callers in coroutine machinery should return the result 30   Callers in coroutine machinery should return the result
31   for symmetric transfer. Callers at the scheduler pump 31   for symmetric transfer. Callers at the scheduler pump
32   level should call `.resume()` on the result. 32   level should call `.resume()` on the result.
33   33  
34   @note A `dispatch` that throws calls `std::terminate`. 34   @note A `dispatch` that throws calls `std::terminate`.
35   35  
36   @param ex The executor to dispatch through. 36   @param ex The executor to dispatch through.
37   @param c The continuation to dispatch. Must remain at a 37   @param c The continuation to dispatch. Must remain at a
38   stable address until dequeued by the executor. 38   stable address until dequeued by the executor.
39   39  
40   @return A handle for symmetric transfer or `std::noop_coroutine()`. 40   @return A handle for symmetric transfer or `std::noop_coroutine()`.
41   */ 41   */
42   inline std::coroutine_handle<> 42   inline std::coroutine_handle<>
HITCBC 43   467398 dispatch_coro(capy::executor_ref ex, capy::continuation& c) noexcept 43   490548 dispatch_coro(capy::executor_ref ex, capy::continuation& c) noexcept
44   { 44   {
45   // An exception from dispatch would leave the completed operation 45   // An exception from dispatch would leave the completed operation
46   // with nobody to resume or abandon its coroutine. 46   // with nobody to resume or abandon its coroutine.
47   // A completion from another context must not resume the awaiter 47   // A completion from another context must not resume the awaiter
48   // on this thread, so the fast path still asks the executor. 48   // on this thread, so the fast path still asks the executor.
HITCBC 49   467398 if (auto const* io_ex = ex.target<io_context::executor_type>()) 49   490548 if (auto const* io_ex = ex.target<io_context::executor_type>())
HITCBC 50   466372 return io_ex->dispatch(c); 50   489417 return io_ex->dispatch(c);
HITCBC 51   1026 return ex.dispatch(c); 51   1131 return ex.dispatch(c);
52   } 52   }
53   53  
54   } // namespace boost::corosio::detail 54   } // namespace boost::corosio::detail
55   55  
56   #endif 56   #endif