]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/impl/resolver_service_base.ipp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / detail / impl / resolver_service_base.ipp
1 //
2 // detail/impl/resolver_service_base.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/resolver_service_base.hpp>
20
21 #include <boost/asio/detail/push_options.hpp>
22
23 namespace boost {
24 namespace asio {
25 namespace detail {
26
27 class resolver_service_base::work_scheduler_runner
28 {
29 public:
30 work_scheduler_runner(scheduler_impl& work_scheduler)
31 : work_scheduler_(work_scheduler)
32 {
33 }
34
35 void operator()()
36 {
37 boost::system::error_code ec;
38 work_scheduler_.run(ec);
39 }
40
41 private:
42 scheduler_impl& work_scheduler_;
43 };
44
45 resolver_service_base::resolver_service_base(execution_context& context)
46 : scheduler_(boost::asio::use_service<scheduler_impl>(context)),
47 work_scheduler_(new scheduler_impl(context, -1, false)),
48 work_thread_(0)
49 {
50 work_scheduler_->work_started();
51 }
52
53 resolver_service_base::~resolver_service_base()
54 {
55 base_shutdown();
56 }
57
58 void resolver_service_base::base_shutdown()
59 {
60 if (work_scheduler_.get())
61 {
62 work_scheduler_->work_finished();
63 work_scheduler_->stop();
64 if (work_thread_.get())
65 {
66 work_thread_->join();
67 work_thread_.reset();
68 }
69 work_scheduler_.reset();
70 }
71 }
72
73 void resolver_service_base::base_notify_fork(
74 execution_context::fork_event fork_ev)
75 {
76 if (work_thread_.get())
77 {
78 if (fork_ev == execution_context::fork_prepare)
79 {
80 work_scheduler_->stop();
81 work_thread_->join();
82 work_thread_.reset();
83 }
84 else
85 {
86 work_scheduler_->restart();
87 work_thread_.reset(new boost::asio::detail::thread(
88 work_scheduler_runner(*work_scheduler_)));
89 }
90 }
91 }
92
93 void resolver_service_base::construct(
94 resolver_service_base::implementation_type& impl)
95 {
96 impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
97 }
98
99 void resolver_service_base::destroy(
100 resolver_service_base::implementation_type& impl)
101 {
102 BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(),
103 "resolver", &impl, 0, "cancel"));
104
105 impl.reset();
106 }
107
108 void resolver_service_base::move_construct(implementation_type& impl,
109 implementation_type& other_impl)
110 {
111 impl = BOOST_ASIO_MOVE_CAST(implementation_type)(other_impl);
112 }
113
114 void resolver_service_base::move_assign(implementation_type& impl,
115 resolver_service_base&, implementation_type& other_impl)
116 {
117 destroy(impl);
118 impl = BOOST_ASIO_MOVE_CAST(implementation_type)(other_impl);
119 }
120
121 void resolver_service_base::cancel(
122 resolver_service_base::implementation_type& impl)
123 {
124 BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(),
125 "resolver", &impl, 0, "cancel"));
126
127 impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
128 }
129
130 void resolver_service_base::start_resolve_op(resolve_op* op)
131 {
132 if (BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(SCHEDULER,
133 scheduler_.concurrency_hint()))
134 {
135 start_work_thread();
136 scheduler_.work_started();
137 work_scheduler_->post_immediate_completion(op, false);
138 }
139 else
140 {
141 op->ec_ = boost::asio::error::operation_not_supported;
142 scheduler_.post_immediate_completion(op, false);
143 }
144 }
145
146 void resolver_service_base::start_work_thread()
147 {
148 boost::asio::detail::mutex::scoped_lock lock(mutex_);
149 if (!work_thread_.get())
150 {
151 work_thread_.reset(new boost::asio::detail::thread(
152 work_scheduler_runner(*work_scheduler_)));
153 }
154 }
155
156 } // namespace detail
157 } // namespace asio
158 } // namespace boost
159
160 #include <boost/asio/detail/pop_options.hpp>
161
162 #endif // BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP