libs/corosio/src/corosio/src/detail/resume_coro.hpp

100.0% Lines (3/3) 100.0% Functions (1/1) -% Branches (0/0)
libs/corosio/src/corosio/src/detail/resume_coro.hpp
Line Hits Source Code
1 //
2 // Copyright (c) 2026 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_DETAIL_RESUME_CORO_HPP
11 #define BOOST_COROSIO_DETAIL_RESUME_CORO_HPP
12
13 #include <boost/capy/ex/executor_ref.hpp>
14 #include <boost/capy/coro.hpp>
15 #include <atomic>
16
17 namespace boost::corosio::detail {
18
19 /** Resumes a coroutine with proper memory synchronization.
20
21 The acquire fence ensures all I/O results (buffer contents,
22 error codes, bytes transferred) written by other threads are
23 visible to the resumed coroutine before it continues execution.
24
25 @param d The executor to dispatch through.
26 @param h The coroutine handle to resume.
27 */
28 inline void
29 107190 resume_coro(capy::executor_ref d, capy::coro h)
30 {
31 // I/O results may have been written by another thread (OS or worker).
32 // Acquire fence ensures those writes are visible before coroutine resumes.
33 std::atomic_thread_fence(std::memory_order_acquire);
34 107190 d.dispatch(h);
35 107190 }
36
37 } // namespace boost::corosio::detail
38
39 #endif
40