select_reactor.hpp 2.3 KB

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