timer_queue_ptime.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // detail/timer_queue_ptime.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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. #ifndef BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
  11. #define BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  17. #include <boost/asio/time_traits.hpp>
  18. #include <boost/asio/detail/timer_queue.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. struct forwarding_posix_time_traits : time_traits<boost::posix_time::ptime> {};
  24. // Template specialisation for the commonly used instantation.
  25. template <>
  26. class timer_queue<time_traits<boost::posix_time::ptime> >
  27. : public timer_queue_base
  28. {
  29. public:
  30. // The time type.
  31. typedef boost::posix_time::ptime time_type;
  32. // The duration type.
  33. typedef boost::posix_time::time_duration duration_type;
  34. // Per-timer data.
  35. typedef timer_queue<forwarding_posix_time_traits>::per_timer_data
  36. per_timer_data;
  37. // Constructor.
  38. BOOST_ASIO_DECL timer_queue();
  39. // Destructor.
  40. BOOST_ASIO_DECL virtual ~timer_queue();
  41. // Add a new timer to the queue. Returns true if this is the timer that is
  42. // earliest in the queue, in which case the reactor's event demultiplexing
  43. // function call may need to be interrupted and restarted.
  44. BOOST_ASIO_DECL bool enqueue_timer(const time_type& time,
  45. per_timer_data& timer, wait_op* op);
  46. // Whether there are no timers in the queue.
  47. BOOST_ASIO_DECL virtual bool empty() const;
  48. // Get the time for the timer that is earliest in the queue.
  49. BOOST_ASIO_DECL virtual long wait_duration_msec(long max_duration) const;
  50. // Get the time for the timer that is earliest in the queue.
  51. BOOST_ASIO_DECL virtual long wait_duration_usec(long max_duration) const;
  52. // Dequeue all timers not later than the current time.
  53. BOOST_ASIO_DECL virtual void get_ready_timers(op_queue<operation>& ops);
  54. // Dequeue all timers.
  55. BOOST_ASIO_DECL virtual void get_all_timers(op_queue<operation>& ops);
  56. // Cancel and dequeue operations for the given timer.
  57. BOOST_ASIO_DECL std::size_t cancel_timer(
  58. per_timer_data& timer, op_queue<operation>& ops,
  59. std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
  60. // Move operations from one timer to another, empty timer.
  61. BOOST_ASIO_DECL void move_timer(per_timer_data& target,
  62. per_timer_data& source);
  63. private:
  64. timer_queue<forwarding_posix_time_traits> impl_;
  65. };
  66. } // namespace detail
  67. } // namespace asio
  68. } // namespace boost
  69. #include <boost/asio/detail/pop_options.hpp>
  70. #if defined(BOOST_ASIO_HEADER_ONLY)
  71. # include <boost/asio/detail/impl/timer_queue_ptime.ipp>
  72. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  73. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  74. #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP