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