kqueue_reactor.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // detail/impl/kqueue_reactor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
  12. #define 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 "asio/detail/config.hpp"
  17. #if defined(ASIO_HAS_KQUEUE)
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. template <typename Time_Traits>
  22. void kqueue_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
  23. {
  24. do_add_timer_queue(queue);
  25. }
  26. // Remove a timer queue from the reactor.
  27. template <typename Time_Traits>
  28. void kqueue_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
  29. {
  30. do_remove_timer_queue(queue);
  31. }
  32. template <typename Time_Traits>
  33. void kqueue_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
  34. const typename Time_Traits::time_type& time,
  35. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
  36. {
  37. asio::detail::mutex::scoped_lock lock(mutex_);
  38. if (shutdown_)
  39. {
  40. io_service_.post_immediate_completion(op, false);
  41. return;
  42. }
  43. bool earliest = queue.enqueue_timer(time, timer, op);
  44. io_service_.work_started();
  45. if (earliest)
  46. interrupt();
  47. }
  48. template <typename Time_Traits>
  49. std::size_t kqueue_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
  50. typename timer_queue<Time_Traits>::per_timer_data& timer,
  51. std::size_t max_cancelled)
  52. {
  53. asio::detail::mutex::scoped_lock lock(mutex_);
  54. op_queue<operation> ops;
  55. std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
  56. lock.unlock();
  57. io_service_.post_deferred_completions(ops);
  58. return n;
  59. }
  60. } // namespace detail
  61. } // namespace asio
  62. #include "asio/detail/pop_options.hpp"
  63. #endif // defined(ASIO_HAS_KQUEUE)
  64. #endif // ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP