kqueue_reactor.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // detail/impl/kqueue_reactor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Copyright (c) 2005 Stefan Arentz (stefan at soze dot com)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
  12. #define BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #if defined(BOOST_ASIO_HAS_KQUEUE)
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. template <typename Time_Traits>
  23. void kqueue_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
  24. {
  25. do_add_timer_queue(queue);
  26. }
  27. // Remove a timer queue from the reactor.
  28. template <typename Time_Traits>
  29. void kqueue_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
  30. {
  31. do_remove_timer_queue(queue);
  32. }
  33. template <typename Time_Traits>
  34. void kqueue_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
  35. const typename Time_Traits::time_type& time,
  36. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
  37. {
  38. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  39. if (shutdown_)
  40. {
  41. io_service_.post_immediate_completion(op, false);
  42. return;
  43. }
  44. bool earliest = queue.enqueue_timer(time, timer, op);
  45. io_service_.work_started();
  46. if (earliest)
  47. interrupt();
  48. }
  49. template <typename Time_Traits>
  50. std::size_t kqueue_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
  51. typename timer_queue<Time_Traits>::per_timer_data& timer,
  52. std::size_t max_cancelled)
  53. {
  54. boost::asio::detail::mutex::scoped_lock lock(mutex_);
  55. op_queue<operation> ops;
  56. std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
  57. lock.unlock();
  58. io_service_.post_deferred_completions(ops);
  59. return n;
  60. }
  61. } // namespace detail
  62. } // namespace asio
  63. } // namespace boost
  64. #include <boost/asio/detail/pop_options.hpp>
  65. #endif // defined(BOOST_ASIO_HAS_KQUEUE)
  66. #endif // BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP