src/corosio/src/detail/dispatch_coro.hpp
100.0% Lines (4/4)
100.0% Functions (1/1)
src/corosio/src/detail/dispatch_coro.hpp
| Line | 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 | 672325 | dispatch_coro(capy::executor_ref ex, std::coroutine_handle<> h) |
| 38 | { | |
| 39 | 672325 | if (ex.target<basic_io_context::executor_type>() != nullptr) |
| 40 | 672316 | return h; |
| 41 | 9 | return ex.dispatch(h); |
| 42 | } | |
| 43 | ||
| 44 | } // namespace boost::corosio::detail | |
| 45 | ||
| 46 | #endif | |
| 47 |