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.

86 lines
2.5KB

  1. //
  2. // impl/system_executor.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_IMPL_SYSTEM_EXECUTOR_HPP
  11. #define ASIO_IMPL_SYSTEM_EXECUTOR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/executor_op.hpp"
  16. #include "asio/detail/global.hpp"
  17. #include "asio/detail/recycling_allocator.hpp"
  18. #include "asio/detail/type_traits.hpp"
  19. #include "asio/system_context.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. inline system_context& system_executor::context() const ASIO_NOEXCEPT
  23. {
  24. return detail::global<system_context>();
  25. }
  26. template <typename Function, typename Allocator>
  27. void system_executor::dispatch(
  28. ASIO_MOVE_ARG(Function) f, const Allocator&) const
  29. {
  30. typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f));
  31. asio_handler_invoke_helpers::invoke(tmp, tmp);
  32. }
  33. template <typename Function, typename Allocator>
  34. void system_executor::post(
  35. ASIO_MOVE_ARG(Function) f, const Allocator& a) const
  36. {
  37. typedef typename decay<Function>::type function_type;
  38. system_context& ctx = detail::global<system_context>();
  39. // Allocate and construct an operation to wrap the function.
  40. typedef detail::executor_op<function_type, Allocator> op;
  41. typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
  42. p.p = new (p.v) op(ASIO_MOVE_CAST(Function)(f), a);
  43. ASIO_HANDLER_CREATION((ctx, *p.p,
  44. "system_executor", &this->context(), 0, "post"));
  45. ctx.scheduler_.post_immediate_completion(p.p, false);
  46. p.v = p.p = 0;
  47. }
  48. template <typename Function, typename Allocator>
  49. void system_executor::defer(
  50. ASIO_MOVE_ARG(Function) f, const Allocator& a) const
  51. {
  52. typedef typename decay<Function>::type function_type;
  53. system_context& ctx = detail::global<system_context>();
  54. // Allocate and construct an operation to wrap the function.
  55. typedef detail::executor_op<function_type, Allocator> op;
  56. typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
  57. p.p = new (p.v) op(ASIO_MOVE_CAST(Function)(f), a);
  58. ASIO_HANDLER_CREATION((ctx, *p.p,
  59. "system_executor", &this->context(), 0, "defer"));
  60. ctx.scheduler_.post_immediate_completion(p.p, true);
  61. p.v = p.p = 0;
  62. }
  63. } // namespace asio
  64. #include "asio/detail/pop_options.hpp"
  65. #endif // ASIO_IMPL_SYSTEM_EXECUTOR_HPP