2 // detail/timer_queue_ptime.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
12 #define BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
22 #include <boost/asio/time_traits.hpp>
23 #include <boost/asio/detail/timer_queue.hpp>
25 #include <boost/asio/detail/push_options.hpp>
31 struct forwarding_posix_time_traits : time_traits<boost::posix_time::ptime> {};
33 // Template specialisation for the commonly used instantation.
35 class timer_queue<time_traits<boost::posix_time::ptime> >
36 : public timer_queue_base
40 typedef boost::posix_time::ptime time_type;
43 typedef boost::posix_time::time_duration duration_type;
46 typedef timer_queue<forwarding_posix_time_traits>::per_timer_data
50 BOOST_ASIO_DECL timer_queue();
53 BOOST_ASIO_DECL virtual ~timer_queue();
55 // Add a new timer to the queue. Returns true if this is the timer that is
56 // earliest in the queue, in which case the reactor's event demultiplexing
57 // function call may need to be interrupted and restarted.
58 BOOST_ASIO_DECL bool enqueue_timer(const time_type& time,
59 per_timer_data& timer, wait_op* op);
61 // Whether there are no timers in the queue.
62 BOOST_ASIO_DECL virtual bool empty() const;
64 // Get the time for the timer that is earliest in the queue.
65 BOOST_ASIO_DECL virtual long wait_duration_msec(long max_duration) const;
67 // Get the time for the timer that is earliest in the queue.
68 BOOST_ASIO_DECL virtual long wait_duration_usec(long max_duration) const;
70 // Dequeue all timers not later than the current time.
71 BOOST_ASIO_DECL virtual void get_ready_timers(op_queue<operation>& ops);
73 // Dequeue all timers.
74 BOOST_ASIO_DECL virtual void get_all_timers(op_queue<operation>& ops);
76 // Cancel and dequeue operations for the given timer.
77 BOOST_ASIO_DECL std::size_t cancel_timer(
78 per_timer_data& timer, op_queue<operation>& ops,
79 std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
81 // Move operations from one timer to another, empty timer.
82 BOOST_ASIO_DECL void move_timer(per_timer_data& target,
83 per_timer_data& source);
86 timer_queue<forwarding_posix_time_traits> impl_;
93 #include <boost/asio/detail/pop_options.hpp>
95 #if defined(BOOST_ASIO_HEADER_ONLY)
96 # include <boost/asio/detail/impl/timer_queue_ptime.ipp>
97 #endif // defined(BOOST_ASIO_HEADER_ONLY)
99 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
101 #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP