]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/waitable_timer_service.hpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / boost / asio / waitable_timer_service.hpp
1 //
2 // waitable_timer_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2018 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_WAITABLE_TIMER_SERVICE_HPP
12 #define BOOST_ASIO_WAITABLE_TIMER_SERVICE_HPP
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
20 #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
21
22 #include <cstddef>
23 #include <boost/asio/async_result.hpp>
24 #include <boost/asio/detail/chrono_time_traits.hpp>
25 #include <boost/asio/detail/deadline_timer_service.hpp>
26 #include <boost/asio/io_context.hpp>
27 #include <boost/asio/wait_traits.hpp>
28
29 #include <boost/asio/detail/push_options.hpp>
30
31 namespace boost {
32 namespace asio {
33
34 /// Default service implementation for a timer.
35 template <typename Clock,
36 typename WaitTraits = boost::asio::wait_traits<Clock> >
37 class waitable_timer_service
38 #if defined(GENERATING_DOCUMENTATION)
39 : public boost::asio::io_context::service
40 #else
41 : public boost::asio::detail::service_base<
42 waitable_timer_service<Clock, WaitTraits> >
43 #endif
44 {
45 public:
46 #if defined(GENERATING_DOCUMENTATION)
47 /// The unique service identifier.
48 static boost::asio::io_context::id id;
49 #endif
50
51 /// The clock type.
52 typedef Clock clock_type;
53
54 /// The duration type of the clock.
55 typedef typename clock_type::duration duration;
56
57 /// The time point type of the clock.
58 typedef typename clock_type::time_point time_point;
59
60 /// The wait traits type.
61 typedef WaitTraits traits_type;
62
63 private:
64 // The type of the platform-specific implementation.
65 typedef detail::deadline_timer_service<
66 detail::chrono_time_traits<Clock, WaitTraits> > service_impl_type;
67
68 public:
69 /// The implementation type of the waitable timer.
70 #if defined(GENERATING_DOCUMENTATION)
71 typedef implementation_defined implementation_type;
72 #else
73 typedef typename service_impl_type::implementation_type implementation_type;
74 #endif
75
76 /// Construct a new timer service for the specified io_context.
77 explicit waitable_timer_service(boost::asio::io_context& io_context)
78 : boost::asio::detail::service_base<
79 waitable_timer_service<Clock, WaitTraits> >(io_context),
80 service_impl_(io_context)
81 {
82 }
83
84 /// Construct a new timer implementation.
85 void construct(implementation_type& impl)
86 {
87 service_impl_.construct(impl);
88 }
89
90 /// Destroy a timer implementation.
91 void destroy(implementation_type& impl)
92 {
93 service_impl_.destroy(impl);
94 }
95
96 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
97 /// Move-construct a new timer implementation.
98 void move_construct(implementation_type& impl,
99 implementation_type& other_impl)
100 {
101 service_impl_.move_construct(impl, other_impl);
102 }
103
104 /// Move-assign from another timer implementation.
105 void move_assign(implementation_type& impl,
106 waitable_timer_service& other_service,
107 implementation_type& other_impl)
108 {
109 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
110 }
111 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
112
113 /// Cancel any asynchronous wait operations associated with the timer.
114 std::size_t cancel(implementation_type& impl, boost::system::error_code& ec)
115 {
116 return service_impl_.cancel(impl, ec);
117 }
118
119 /// Cancels one asynchronous wait operation associated with the timer.
120 std::size_t cancel_one(implementation_type& impl,
121 boost::system::error_code& ec)
122 {
123 return service_impl_.cancel_one(impl, ec);
124 }
125
126 #if !defined(BOOST_ASIO_NO_DEPRECATED)
127 /// (Deprecated: Use expiry().) Get the expiry time for the timer as an
128 /// absolute time.
129 time_point expires_at(const implementation_type& impl) const
130 {
131 return service_impl_.expiry(impl);
132 }
133 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
134
135 /// Get the expiry time for the timer as an absolute time.
136 time_point expiry(const implementation_type& impl) const
137 {
138 return service_impl_.expiry(impl);
139 }
140
141 /// Set the expiry time for the timer as an absolute time.
142 std::size_t expires_at(implementation_type& impl,
143 const time_point& expiry_time, boost::system::error_code& ec)
144 {
145 return service_impl_.expires_at(impl, expiry_time, ec);
146 }
147
148 /// Set the expiry time for the timer relative to now.
149 std::size_t expires_after(implementation_type& impl,
150 const duration& expiry_time, boost::system::error_code& ec)
151 {
152 return service_impl_.expires_after(impl, expiry_time, ec);
153 }
154
155 #if !defined(BOOST_ASIO_NO_DEPRECATED)
156 /// (Deprecated: Use expiry().) Get the expiry time for the timer relative to
157 /// now.
158 duration expires_from_now(const implementation_type& impl) const
159 {
160 typedef detail::chrono_time_traits<Clock, WaitTraits> traits;
161 return traits::subtract(service_impl_.expiry(impl), traits::now());
162 }
163
164 /// (Deprecated: Use expires_after().) Set the expiry time for the timer
165 /// relative to now.
166 std::size_t expires_from_now(implementation_type& impl,
167 const duration& expiry_time, boost::system::error_code& ec)
168 {
169 return service_impl_.expires_after(impl, expiry_time, ec);
170 }
171 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
172
173 // Perform a blocking wait on the timer.
174 void wait(implementation_type& impl, boost::system::error_code& ec)
175 {
176 service_impl_.wait(impl, ec);
177 }
178
179 // Start an asynchronous wait on the timer.
180 template <typename WaitHandler>
181 BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
182 void (boost::system::error_code))
183 async_wait(implementation_type& impl,
184 BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
185 {
186 async_completion<WaitHandler,
187 void (boost::system::error_code)> init(handler);
188
189 service_impl_.async_wait(impl, init.completion_handler);
190
191 return init.result.get();
192 }
193
194 private:
195 // Destroy all user-defined handler objects owned by the service.
196 void shutdown()
197 {
198 service_impl_.shutdown();
199 }
200
201 // The platform-specific implementation.
202 service_impl_type service_impl_;
203 };
204
205 } // namespace asio
206 } // namespace boost
207
208 #include <boost/asio/detail/pop_options.hpp>
209
210 #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
211
212 #endif // BOOST_ASIO_WAITABLE_TIMER_SERVICE_HPP