1919#include < cstddef>
2020#include " asio/associated_cancellation_slot.hpp"
2121#include " asio/cancellation_type.hpp"
22+ #include " asio/config.hpp"
2223#include " asio/error.hpp"
2324#include " asio/execution_context.hpp"
2425#include " asio/detail/bind_handler.hpp"
4344namespace asio {
4445namespace detail {
4546
46- template <typename Time_Traits >
47+ template <typename TimeTraits >
4748class deadline_timer_service
48- : public execution_context_service_base<deadline_timer_service<Time_Traits >>
49+ : public execution_context_service_base<deadline_timer_service<TimeTraits >>
4950{
5051public:
5152 // The time type.
52- typedef typename Time_Traits ::time_type time_type;
53+ typedef typename TimeTraits ::time_type time_type;
5354
5455 // The duration type.
55- typedef typename Time_Traits::duration_type duration_type;
56+ typedef typename TimeTraits::duration_type duration_type;
57+
58+ // The allocator type.
59+ typedef execution_context::allocator<void > allocator_type;
5660
5761 // The implementation type of the timer. This type is dependent on the
5862 // underlying implementation of the timer service.
@@ -61,13 +65,15 @@ class deadline_timer_service
6165 {
6266 time_type expiry;
6367 bool might_have_pending_waits;
64- typename timer_queue<Time_Traits >::per_timer_data timer_data;
68+ typename timer_queue<TimeTraits, allocator_type >::per_timer_data timer_data;
6569 };
6670
6771 // Constructor.
6872 deadline_timer_service (execution_context& context)
6973 : execution_context_service_base<
70- deadline_timer_service<Time_Traits>>(context),
74+ deadline_timer_service<TimeTraits>>(context),
75+ timer_queue_ (allocator_type(context),
76+ config (context).get(" timer" , " heap_reserve" , 0U )),
7177 scheduler_ (asio::use_service<timer_scheduler>(context))
7278 {
7379 scheduler_.init_task ();
@@ -204,7 +210,7 @@ class deadline_timer_service
204210 // Get the expiry time for the timer relative to now.
205211 duration_type expires_from_now (const implementation_type& impl) const
206212 {
207- return Time_Traits ::subtract (this ->expiry (impl), Time_Traits ::now ());
213+ return TimeTraits ::subtract (this ->expiry (impl), TimeTraits ::now ());
208214 }
209215
210216 // Set the expiry time for the timer as an absolute time.
@@ -222,27 +228,27 @@ class deadline_timer_service
222228 const duration_type& expiry_time, asio::error_code& ec)
223229 {
224230 return expires_at (impl,
225- Time_Traits ::add (Time_Traits ::now (), expiry_time), ec);
231+ TimeTraits ::add (TimeTraits ::now (), expiry_time), ec);
226232 }
227233
228234 // Set the expiry time for the timer relative to now.
229235 std::size_t expires_from_now (implementation_type& impl,
230236 const duration_type& expiry_time, asio::error_code& ec)
231237 {
232238 return expires_at (impl,
233- Time_Traits ::add (Time_Traits ::now (), expiry_time), ec);
239+ TimeTraits ::add (TimeTraits ::now (), expiry_time), ec);
234240 }
235241
236242 // Perform a blocking wait on the timer.
237243 void wait (implementation_type& impl, asio::error_code& ec)
238244 {
239- time_type now = Time_Traits ::now ();
245+ time_type now = TimeTraits ::now ();
240246 ec = asio::error_code ();
241- while (Time_Traits ::less_than (now, impl.expiry ) && !ec)
247+ while (TimeTraits ::less_than (now, impl.expiry ) && !ec)
242248 {
243- this ->do_wait (Time_Traits ::to_posix_duration (
244- Time_Traits ::subtract (impl.expiry , now)), ec);
245- now = Time_Traits ::now ();
249+ this ->do_wait (TimeTraits ::to_posix_duration (
250+ TimeTraits ::subtract (impl.expiry , now)), ec);
251+ now = TimeTraits ::now ();
246252 }
247253 }
248254
@@ -301,7 +307,7 @@ class deadline_timer_service
301307 {
302308 public:
303309 op_cancellation (deadline_timer_service* s,
304- typename timer_queue<Time_Traits >::per_timer_data* p)
310+ typename timer_queue<TimeTraits, allocator_type >::per_timer_data* p)
305311 : service_(s),
306312 timer_data_ (p)
307313 {
@@ -321,11 +327,12 @@ class deadline_timer_service
321327
322328 private:
323329 deadline_timer_service* service_;
324- typename timer_queue<Time_Traits>::per_timer_data* timer_data_;
330+ typename timer_queue<TimeTraits, allocator_type>::per_timer_data*
331+ timer_data_;
325332 };
326333
327334 // The queue of timers.
328- timer_queue<Time_Traits > timer_queue_;
335+ timer_queue<TimeTraits, allocator_type > timer_queue_;
329336
330337 // The object that schedules and executes timers. Usually a reactor.
331338 timer_scheduler& scheduler_;
0 commit comments