libs/corosio/src/corosio/src/detail/dispatch_coro.hpp
100.0% Lines (4/4)
100.0% Functions (1/1)
100.0% Branches (2/2)
libs/corosio/src/corosio/src/detail/dispatch_coro.hpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2026 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2026 Steve Gerbino | ||
| 4 | // | ||
| 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) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/corosio | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP | ||
| 12 | #define BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP | ||
| 13 | |||
| 14 | #include <boost/corosio/basic_io_context.hpp> | ||
| 15 | #include <boost/capy/ex/executor_ref.hpp> | ||
| 16 | #include <boost/capy/detail/type_id.hpp> | ||
| 17 | #include <coroutine> | ||
| 18 | |||
| 19 | namespace boost::corosio::detail { | ||
| 20 | |||
| 21 | /** Returns a handle for symmetric transfer on I/O completion. | ||
| 22 | |||
| 23 | If the executor is io_context::executor_type, returns `h` | ||
| 24 | directly (fast path). Otherwise dispatches through the | ||
| 25 | executor, which returns `h` or `noop_coroutine()`. | ||
| 26 | |||
| 27 | Callers in coroutine machinery should return the result | ||
| 28 | for symmetric transfer. Callers at the scheduler pump | ||
| 29 | level should call `.resume()` on the result. | ||
| 30 | |||
| 31 | @param ex The executor to dispatch through. | ||
| 32 | @param h The coroutine handle to resume. | ||
| 33 | |||
| 34 | @return A handle for symmetric transfer or `std::noop_coroutine()`. | ||
| 35 | */ | ||
| 36 | inline std::coroutine_handle<> | ||
| 37 | 248023 | dispatch_coro( | |
| 38 | capy::executor_ref ex, | ||
| 39 | std::coroutine_handle<> h) | ||
| 40 | { | ||
| 41 |
2/2✓ Branch 1 taken 248014 times.
✓ Branch 2 taken 9 times.
|
248023 | if ( ex.target< basic_io_context::executor_type >() ) |
| 42 | 248014 | return h; | |
| 43 | 9 | return ex.dispatch(h); | |
| 44 | } | ||
| 45 | |||
| 46 | } // namespace boost::corosio::detail | ||
| 47 | |||
| 48 | #endif | ||
| 49 |