timer_queue_set.ipp 2.2 KB

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