/Src/Dependencies/Boost/boost/asio/detail/impl/select_reactor.hpp

http://hadesmem.googlecode.com/ · C++ Header · 87 lines · 58 code · 16 blank · 13 comment · 6 complexity · 8d7d9997d953b467745fe75d13eae402 MD5 · raw file

  1. //
  2. // detail/impl/select_reactor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 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. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  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, timer_op* op)
  39. {
  40. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  41. if (shutdown_)
  42. {
  43. io_service_.post_immediate_completion(op);
  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. boost::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. } // namespace boost
  66. #include <boost/asio/detail/pop_options.hpp>
  67. #endif // defined(BOOST_ASIO_HAS_IOCP)
  68. // || (!defined(BOOST_ASIO_HAS_DEV_POLL)
  69. // && !defined(BOOST_ASIO_HAS_EPOLL)
  70. // && !defined(BOOST_ASIO_HAS_KQUEUE))
  71. #endif // BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP