TLA Line data Source code
1 : //
2 : // Copyright (c) 2026 Steve Gerbino
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_NATIVE_DETAIL_REACTOR_REACTOR_SERVICE_STATE_HPP
11 : #define BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SERVICE_STATE_HPP
12 :
13 : #include <boost/corosio/detail/intrusive.hpp>
14 :
15 : #include <memory>
16 : #include <mutex>
17 : #include <unordered_map>
18 :
19 : namespace boost::corosio::detail {
20 :
21 : /** Shared service state for reactor backends.
22 :
23 : Holds the scheduler reference, service mutex, and per-impl
24 : ownership tracking. Used by both socket and acceptor services.
25 :
26 : @tparam Scheduler The backend's scheduler type.
27 : @tparam Impl The backend's socket or acceptor impl type.
28 : */
29 : template <class Scheduler, class Impl>
30 : struct reactor_service_state
31 : {
32 : /// Construct with a reference to the owning scheduler.
33 HIT 824 : explicit reactor_service_state(Scheduler& sched) noexcept
34 824 : : sched_(sched)
35 : {
36 824 : }
37 :
38 : /// Reference to the owning scheduler.
39 : Scheduler& sched_;
40 :
41 : /// Protects `impl_list_` and `impl_ptrs_`.
42 : std::mutex mutex_;
43 :
44 : /// All live impl objects for shutdown traversal.
45 : intrusive_list<Impl> impl_list_;
46 :
47 : /// Shared ownership of each impl, keyed by raw pointer.
48 : std::unordered_map<Impl*, std::shared_ptr<Impl>> impl_ptrs_;
49 : };
50 :
51 : } // namespace boost::corosio::detail
52 :
53 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SERVICE_STATE_HPP
|