Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

handler_work.hpp 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // detail/handler_work.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_HANDLER_WORK_HPP
  11. #define ASIO_DETAIL_HANDLER_WORK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/associated_executor.hpp"
  17. #include "asio/detail/handler_invoke_helpers.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. // A helper class template to allow completion handlers to be dispatched
  22. // through either the new executors framework or the old invocaton hook. The
  23. // primary template uses the new executors framework.
  24. template <typename Handler, typename Executor
  25. = typename associated_executor<Handler>::type>
  26. class handler_work
  27. {
  28. public:
  29. explicit handler_work(Handler& handler) ASIO_NOEXCEPT
  30. : executor_(associated_executor<Handler>::get(handler))
  31. {
  32. }
  33. static void start(Handler& handler) ASIO_NOEXCEPT
  34. {
  35. Executor ex(associated_executor<Handler>::get(handler));
  36. ex.on_work_started();
  37. }
  38. ~handler_work()
  39. {
  40. executor_.on_work_finished();
  41. }
  42. template <typename Function>
  43. void complete(Function& function, Handler& handler)
  44. {
  45. executor_.dispatch(ASIO_MOVE_CAST(Function)(function),
  46. associated_allocator<Handler>::get(handler));
  47. }
  48. private:
  49. // Disallow copying and assignment.
  50. handler_work(const handler_work&);
  51. handler_work& operator=(const handler_work&);
  52. typename associated_executor<Handler>::type executor_;
  53. };
  54. // This specialisation dispatches a handler through the old invocation hook.
  55. // The specialisation is not strictly required for correctness, as the
  56. // system_executor will dispatch through the hook anyway. However, by doing
  57. // this we avoid an extra copy of the handler.
  58. template <typename Handler>
  59. class handler_work<Handler, system_executor>
  60. {
  61. public:
  62. explicit handler_work(Handler&) ASIO_NOEXCEPT {}
  63. static void start(Handler&) ASIO_NOEXCEPT {}
  64. ~handler_work() {}
  65. template <typename Function>
  66. void complete(Function& function, Handler& handler)
  67. {
  68. asio_handler_invoke_helpers::invoke(function, handler);
  69. }
  70. private:
  71. // Disallow copying and assignment.
  72. handler_work(const handler_work&);
  73. handler_work& operator=(const handler_work&);
  74. };
  75. } // namespace detail
  76. } // namespace asio
  77. #include "asio/detail/pop_options.hpp"
  78. #endif // ASIO_DETAIL_HANDLER_WORK_HPP