select_reactor.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // detail/impl/select_reactor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 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_SELECT_REACTOR_HPP
  11. #define BOOST_ASIO_DETAIL_IMPL_SELECT_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_IOCP) \
  17. || (!defined(BOOST_ASIO_HAS_DEV_POLL) \
  18. && !defined(BOOST_ASIO_HAS_EPOLL) \
  19. && !defined(BOOST_ASIO_HAS_KQUEUE) \
  20. && !defined(BOOST_ASIO_WINDOWS_RUNTIME))
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace detail {
  25. template <typename Time_Traits>
  26. void select_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
  27. {
  28. do_add_timer_queue(queue);
  29. }
  30. // Remove a timer queue from the reactor.
  31. template <typename Time_Traits>
  32. void select_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
  33. {
  34. do_remove_timer_queue(queue);
  35. }
  36. template <typename Time_Traits>
  37. void select_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
  38. const typename Time_Traits::time_type& time,
  39. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
  40. {
  41. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  42. if (shutdown_)
  43. {
  44. io_service_.post_immediate_completion(op, false);
  45. return;
  46. }
  47. bool earliest = queue.enqueue_timer(time, timer, op);
  48. io_service_.work_started();
  49. if (earliest)
  50. interrupter_.interrupt();
  51. }
  52. template <typename Time_Traits>
  53. std::size_t select_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
  54. typename timer_queue<Time_Traits>::per_timer_data& timer,
  55. std::size_t max_cancelled)
  56. {
  57. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  58. op_queue<operation> ops;
  59. std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
  60. lock.unlock();
  61. io_service_.post_deferred_completions(ops);
  62. return n;
  63. }
  64. } // namespace detail
  65. } // namespace asio
  66. } // namespace boost
  67. #include <boost/asio/detail/pop_options.hpp>
  68. #endif // defined(BOOST_ASIO_HAS_IOCP)
  69. // || (!defined(BOOST_ASIO_HAS_DEV_POLL)
  70. // && !defined(BOOST_ASIO_HAS_EPOLL)
  71. // && !defined(BOOST_ASIO_HAS_KQUEUE)
  72. // && !defined(BOOST_ASIO_WINDOWS_RUNTIME))
  73. #endif // BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP