timer_queue_set.ipp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // detail/impl/timer_queue_set.ipp
  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. #ifndef BOOST_ASIO_DETAIL_IMPL_TIMER_QUEUE_SET_IPP
  11. #define BOOST_ASIO_DETAIL_IMPL_TIMER_QUEUE_SET_IPP
  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. #include <boost/asio/detail/timer_queue_set.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. timer_queue_set::timer_queue_set()
  22. : first_(0)
  23. {
  24. }
  25. void timer_queue_set::insert(timer_queue_base* q)
  26. {
  27. q->next_ = first_;
  28. first_ = q;
  29. }
  30. void timer_queue_set::erase(timer_queue_base* q)
  31. {
  32. if (first_)
  33. {
  34. if (q == first_)
  35. {
  36. first_ = q->next_;
  37. q->next_ = 0;
  38. return;
  39. }
  40. for (timer_queue_base* p = first_; p->next_; p = p->next_)
  41. {
  42. if (p->next_ == q)
  43. {
  44. p->next_ = q->next_;
  45. q->next_ = 0;
  46. return;
  47. }
  48. }
  49. }
  50. }
  51. bool timer_queue_set::all_empty() const
  52. {
  53. for (timer_queue_base* p = first_; p; p = p->next_)
  54. if (!p->empty())
  55. return false;
  56. return true;
  57. }
  58. long timer_queue_set::wait_duration_msec(long max_duration) const
  59. {
  60. long min_duration = max_duration;
  61. for (timer_queue_base* p = first_; p; p = p->next_)
  62. min_duration = p->wait_duration_msec(min_duration);
  63. return min_duration;
  64. }
  65. long timer_queue_set::wait_duration_usec(long max_duration) const
  66. {
  67. long min_duration = max_duration;
  68. for (timer_queue_base* p = first_; p; p = p->next_)
  69. min_duration = p->wait_duration_usec(min_duration);
  70. return min_duration;
  71. }
  72. void timer_queue_set::get_ready_timers(op_queue<operation>& ops)
  73. {
  74. for (timer_queue_base* p = first_; p; p = p->next_)
  75. p->get_ready_timers(ops);
  76. }
  77. void timer_queue_set::get_all_timers(op_queue<operation>& ops)
  78. {
  79. for (timer_queue_base* p = first_; p; p = p->next_)
  80. p->get_all_timers(ops);
  81. }
  82. } // namespace detail
  83. } // namespace asio
  84. } // namespace boost
  85. #include <boost/asio/detail/pop_options.hpp>
  86. #endif // BOOST_ASIO_DETAIL_IMPL_TIMER_QUEUE_SET_IPP