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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // detail/work_dispatcher.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_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. work_dispatcher(Handler& handler)
  27. : work_((get_associated_executor)(handler)),
  28. handler_(ASIO_MOVE_CAST(Handler)(handler))
  29. {
  30. }
  31. #if defined(ASIO_HAS_MOVE)
  32. work_dispatcher(const work_dispatcher& other)
  33. : work_(other.work_),
  34. handler_(other.handler_)
  35. {
  36. }
  37. work_dispatcher(work_dispatcher&& other)
  38. : work_(ASIO_MOVE_CAST(executor_work_guard<
  39. typename associated_executor<Handler>::type>)(other.work_)),
  40. handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
  41. {
  42. }
  43. #endif // defined(ASIO_HAS_MOVE)
  44. void operator()()
  45. {
  46. typename associated_executor<Handler>::type ex(work_.get_executor());
  47. typename associated_allocator<Handler>::type alloc(
  48. (get_associated_allocator)(handler_));
  49. ex.dispatch(ASIO_MOVE_CAST(Handler)(handler_), alloc);
  50. work_.reset();
  51. }
  52. private:
  53. executor_work_guard<typename associated_executor<Handler>::type> work_;
  54. Handler handler_;
  55. };
  56. } // namespace detail
  57. } // namespace asio
  58. #include "asio/detail/pop_options.hpp"
  59. #endif // ASIO_DETAIL_WORK_DISPATCHER_HPP