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.4KB

  1. //
  2. // detail/wait_handler.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_WAIT_HANDLER_HPP
  11. #define ASIO_DETAIL_WAIT_HANDLER_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/detail/fenced_block.hpp"
  17. #include "asio/detail/handler_alloc_helpers.hpp"
  18. #include "asio/detail/handler_invoke_helpers.hpp"
  19. #include "asio/detail/memory.hpp"
  20. #include "asio/detail/wait_op.hpp"
  21. #include "asio/io_context.hpp"
  22. #include "asio/detail/push_options.hpp"
  23. namespace asio {
  24. namespace detail {
  25. template <typename Handler>
  26. class wait_handler : public wait_op
  27. {
  28. public:
  29. ASIO_DEFINE_HANDLER_PTR(wait_handler);
  30. wait_handler(Handler& h)
  31. : wait_op(&wait_handler::do_complete),
  32. handler_(ASIO_MOVE_CAST(Handler)(h))
  33. {
  34. handler_work<Handler>::start(handler_);
  35. }
  36. static void do_complete(void* owner, operation* base,
  37. const asio::error_code& /*ec*/,
  38. std::size_t /*bytes_transferred*/)
  39. {
  40. // Take ownership of the handler object.
  41. wait_handler* h(static_cast<wait_handler*>(base));
  42. ptr p = { asio::detail::addressof(h->handler_), h, h };
  43. handler_work<Handler> w(h->handler_);
  44. ASIO_HANDLER_COMPLETION((*h));
  45. // Make a copy of the handler so that the memory can be deallocated before
  46. // the upcall is made. Even if we're not about to make an upcall, a
  47. // sub-object of the handler may be the true owner of the memory associated
  48. // with the handler. Consequently, a local copy of the handler is required
  49. // to ensure that any owning sub-object remains valid until after we have
  50. // deallocated the memory here.
  51. detail::binder1<Handler, asio::error_code>
  52. handler(h->handler_, h->ec_);
  53. p.h = asio::detail::addressof(handler.handler_);
  54. p.reset();
  55. // Make the upcall if required.
  56. if (owner)
  57. {
  58. fenced_block b(fenced_block::half);
  59. ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
  60. w.complete(handler, handler.handler_);
  61. ASIO_HANDLER_INVOCATION_END;
  62. }
  63. }
  64. private:
  65. Handler handler_;
  66. };
  67. } // namespace detail
  68. } // namespace asio
  69. #include "asio/detail/pop_options.hpp"
  70. #endif // ASIO_DETAIL_WAIT_HANDLER_HPP