epoll_reactor.hpp 1.9 KB

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