epoll_reactor.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // detail/impl/epoll_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_EPOLL_REACTOR_HPP
  11. #define BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #if defined(BOOST_ASIO_HAS_EPOLL)
  16. #include <boost/asio/detail/push_options.hpp>
  17. namespace boost {
  18. namespace asio {
  19. namespace detail {
  20. template <typename Time_Traits>
  21. void epoll_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
  22. {
  23. do_add_timer_queue(queue);
  24. }
  25. template <typename Time_Traits>
  26. void epoll_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
  27. {
  28. do_remove_timer_queue(queue);
  29. }
  30. template <typename Time_Traits>
  31. void epoll_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
  32. const typename Time_Traits::time_type& time,
  33. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
  34. {
  35. mutex::scoped_lock lock(mutex_);
  36. if (shutdown_)
  37. {
  38. io_service_.post_immediate_completion(op, false);
  39. return;
  40. }
  41. bool earliest = queue.enqueue_timer(time, timer, op);
  42. io_service_.work_started();
  43. if (earliest)
  44. update_timeout();
  45. }
  46. template <typename Time_Traits>
  47. std::size_t epoll_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
  48. typename timer_queue<Time_Traits>::per_timer_data& timer,
  49. std::size_t max_cancelled)
  50. {
  51. mutex::scoped_lock lock(mutex_);
  52. op_queue<operation> ops;
  53. std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
  54. lock.unlock();
  55. io_service_.post_deferred_completions(ops);
  56. return n;
  57. }
  58. } // namespace detail
  59. } // namespace asio
  60. } // namespace boost
  61. #include <boost/asio/detail/pop_options.hpp>
  62. #endif // defined(BOOST_ASIO_HAS_EPOLL)
  63. #endif // BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP