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.

work_dispatcher.hpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // detail/work_dispatcher.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_WORK_DISPATCHER_HPP
  11. #define ASIO_DETAIL_WORK_DISPATCHER_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/associated_allocator.hpp"
  18. #include "asio/executor_work_guard.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. template <typename Handler>
  23. class work_dispatcher
  24. {
  25. public:
  26. template <typename CompletionHandler>
  27. explicit work_dispatcher(ASIO_MOVE_ARG(CompletionHandler) handler)
  28. : work_((get_associated_executor)(handler)),
  29. handler_(ASIO_MOVE_CAST(CompletionHandler)(handler))
  30. {
  31. }
  32. #if defined(ASIO_HAS_MOVE)
  33. work_dispatcher(const work_dispatcher& other)
  34. : work_(other.work_),
  35. handler_(other.handler_)
  36. {
  37. }
  38. work_dispatcher(work_dispatcher&& other)
  39. : work_(ASIO_MOVE_CAST(executor_work_guard<
  40. typename associated_executor<Handler>::type>)(other.work_)),
  41. handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
  42. {
  43. }
  44. #endif // defined(ASIO_HAS_MOVE)
  45. void operator()()
  46. {
  47. typename associated_allocator<Handler>::type alloc(
  48. (get_associated_allocator)(handler_));
  49. work_.get_executor().dispatch(
  50. ASIO_MOVE_CAST(Handler)(handler_), alloc);
  51. work_.reset();
  52. }
  53. private:
  54. executor_work_guard<typename associated_executor<Handler>::type> work_;
  55. Handler handler_;
  56. };
  57. } // namespace detail
  58. } // namespace asio
  59. #include "asio/detail/pop_options.hpp"
  60. #endif // ASIO_DETAIL_WORK_DISPATCHER_HPP