epoll_reactor.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // detail/impl/epoll_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 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, timer_op* op)
  33. {
  34. mutex::scoped_lock lock(mutex_);
  35. if (shutdown_)
  36. {
  37. io_service_.post_immediate_completion(op);
  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. {
  49. mutex::scoped_lock lock(mutex_);
  50. op_queue<operation> ops;
  51. std::size_t n = queue.cancel_timer(timer, ops);
  52. lock.unlock();
  53. io_service_.post_deferred_completions(ops);
  54. return n;
  55. }
  56. } // namespace detail
  57. } // namespace asio
  58. #include "asio/detail/pop_options.hpp"
  59. #endif // defined(ASIO_HAS_EPOLL)
  60. #endif // ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP