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.

100 lines
3.1KB

  1. //
  2. // impl/system_executor.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_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/execution_context.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. inline execution_context& system_executor::context() const ASIO_NOEXCEPT
  23. {
  24. return detail::global<context_impl>();
  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. context_impl& ctx = detail::global<context_impl>();
  38. // Make a local, non-const copy of the function.
  39. typedef typename decay<Function>::type function_type;
  40. function_type tmp(ASIO_MOVE_CAST(Function)(f));
  41. // Construct an allocator to be used for the operation.
  42. typedef typename detail::get_recycling_allocator<Allocator>::type alloc_type;
  43. alloc_type allocator(detail::get_recycling_allocator<Allocator>::get(a));
  44. // Allocate and construct an operation to wrap the function.
  45. typedef detail::executor_op<function_type, alloc_type> op;
  46. typename op::ptr p = { allocator, 0, 0 };
  47. p.v = p.a.allocate(1);
  48. p.p = new (p.v) op(tmp, allocator);
  49. ASIO_HANDLER_CREATION((ctx, *p.p,
  50. "system_executor", &this->context(), 0, "post"));
  51. ctx.scheduler_.post_immediate_completion(p.p, false);
  52. p.v = p.p = 0;
  53. }
  54. template <typename Function, typename Allocator>
  55. void system_executor::defer(
  56. ASIO_MOVE_ARG(Function) f, const Allocator& a) const
  57. {
  58. context_impl& ctx = detail::global<context_impl>();
  59. // Make a local, non-const copy of the function.
  60. typedef typename decay<Function>::type function_type;
  61. function_type tmp(ASIO_MOVE_CAST(Function)(f));
  62. // Construct an allocator to be used for the operation.
  63. typedef typename detail::get_recycling_allocator<Allocator>::type alloc_type;
  64. alloc_type allocator(detail::get_recycling_allocator<Allocator>::get(a));
  65. // Allocate and construct an operation to wrap the function.
  66. typedef detail::executor_op<function_type, alloc_type> op;
  67. typename op::ptr p = { allocator, 0, 0 };
  68. p.v = p.a.allocate(1);
  69. p.p = new (p.v) op(tmp, allocator);
  70. ASIO_HANDLER_CREATION((ctx, *p.p,
  71. "system_executor", &this->context(), 0, "defer"));
  72. ctx.scheduler_.post_immediate_completion(p.p, true);
  73. p.v = p.p = 0;
  74. }
  75. } // namespace asio
  76. #include "asio/detail/pop_options.hpp"
  77. #endif // ASIO_IMPL_SYSTEM_EXECUTOR_HPP