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   If the executor is io_context::executor_type, returns `c.h` 24   If the executor is io_context::executor_type, returns `c.h`
25   directly (fast path). Otherwise dispatches through the 25   directly (fast path). Otherwise dispatches through the
26   executor, which returns `c.h` or `noop_coroutine()`. 26   executor, which returns `c.h` or `noop_coroutine()`.
27   27  
28   Callers in coroutine machinery should return the result 28   Callers in coroutine machinery should return the result
29   for symmetric transfer. Callers at the scheduler pump 29   for symmetric transfer. Callers at the scheduler pump
30   level should call `.resume()` on the result. 30   level should call `.resume()` on the result.
31   31  
32   @param ex The executor to dispatch through. 32   @param ex The executor to dispatch through.
33   @param c The continuation to dispatch. Must remain at a 33   @param c The continuation to dispatch. Must remain at a
34   stable address until dequeued by the executor. 34   stable address until dequeued by the executor.
35   35  
36   @return A handle for symmetric transfer or `std::noop_coroutine()`. 36   @return A handle for symmetric transfer or `std::noop_coroutine()`.
37   */ 37   */
38   inline std::coroutine_handle<> 38   inline std::coroutine_handle<>
HITCBC 39   441950 dispatch_coro(capy::executor_ref ex, capy::continuation& c) 39   462021 dispatch_coro(capy::executor_ref ex, capy::continuation& c)
40   { 40   {
HITCBC 41   441950 if (ex.target<io_context::executor_type>() != nullptr) 41   462021 if (ex.target<io_context::executor_type>() != nullptr)
HITCBC 42   441941 return c.h; 42   462012 return c.h;
HITCBC 43   9 return ex.dispatch(c); 43   9 return ex.dispatch(c);
44   } 44   }
45   45  
46   } // namespace boost::corosio::detail 46   } // namespace boost::corosio::detail
47   47  
48   #endif 48   #endif