dev_poll_reactor.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // detail/impl/dev_poll_reactor.hpp
  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_DEV_POLL_REACTOR_HPP
  11. #define BOOST_ASIO_DETAIL_IMPL_DEV_POLL_REACTOR_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_DEV_POLL)
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. template <typename Time_Traits>
  22. void dev_poll_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
  23. {
  24. do_add_timer_queue(queue);
  25. }
  26. template <typename Time_Traits>
  27. void dev_poll_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
  28. {
  29. do_remove_timer_queue(queue);
  30. }
  31. template <typename Time_Traits>
  32. void dev_poll_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
  33. const typename Time_Traits::time_type& time,
  34. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
  35. {
  36. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  37. if (shutdown_)
  38. {
  39. scheduler_.post_immediate_completion(op, false);
  40. return;
  41. }
  42. bool earliest = queue.enqueue_timer(time, timer, op);
  43. scheduler_.work_started();
  44. if (earliest)
  45. interrupter_.interrupt();
  46. }
  47. template <typename Time_Traits>
  48. std::size_t dev_poll_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
  49. typename timer_queue<Time_Traits>::per_timer_data& timer,
  50. std::size_t max_cancelled)
  51. {
  52. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  53. op_queue<operation> ops;
  54. std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
  55. lock.unlock();
  56. scheduler_.post_deferred_completions(ops);
  57. return n;
  58. }
  59. template <typename Time_Traits>
  60. void dev_poll_reactor::move_timer(timer_queue<Time_Traits>& queue,
  61. typename timer_queue<Time_Traits>::per_timer_data& target,
  62. typename timer_queue<Time_Traits>::per_timer_data& source)
  63. {
  64. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  65. op_queue<operation> ops;
  66. queue.cancel_timer(target, ops);
  67. queue.move_timer(target, source);
  68. lock.unlock();
  69. scheduler_.post_deferred_completions(ops);
  70. }
  71. } // namespace detail
  72. } // namespace asio
  73. } // namespace boost
  74. #include <boost/asio/detail/pop_options.hpp>
  75. #endif // defined(BOOST_ASIO_HAS_DEV_POLL)
  76. #endif // BOOST_ASIO_DETAIL_IMPL_DEV_POLL_REACTOR_HPP