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

  1. //
  2. // handler_invoke_hook.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_HANDLER_INVOKE_HOOK_HPP
  11. #define ASIO_HANDLER_INVOKE_HOOK_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/push_options.hpp"
  17. namespace asio {
  18. /** @defgroup asio_handler_invoke asio::asio_handler_invoke
  19. *
  20. * @brief Default invoke function for handlers.
  21. *
  22. * Completion handlers for asynchronous operations are invoked by the
  23. * io_context associated with the corresponding object (e.g. a socket or
  24. * deadline_timer). Certain guarantees are made on when the handler may be
  25. * invoked, in particular that a handler can only be invoked from a thread that
  26. * is currently calling @c run() on the corresponding io_context object.
  27. * Handlers may subsequently be invoked through other objects (such as
  28. * io_context::strand objects) that provide additional guarantees.
  29. *
  30. * When asynchronous operations are composed from other asynchronous
  31. * operations, all intermediate handlers should be invoked using the same
  32. * method as the final handler. This is required to ensure that user-defined
  33. * objects are not accessed in a way that may violate the guarantees. This
  34. * hooking function ensures that the invoked method used for the final handler
  35. * is accessible at each intermediate step.
  36. *
  37. * Implement asio_handler_invoke for your own handlers to specify a custom
  38. * invocation strategy.
  39. *
  40. * This default implementation invokes the function object like so:
  41. * @code function(); @endcode
  42. * If necessary, the default implementation makes a copy of the function object
  43. * so that the non-const operator() can be used.
  44. *
  45. * @par Example
  46. * @code
  47. * class my_handler;
  48. *
  49. * template <typename Function>
  50. * void asio_handler_invoke(Function function, my_handler* context)
  51. * {
  52. * context->strand_.dispatch(function);
  53. * }
  54. * @endcode
  55. */
  56. /*@{*/
  57. /// Default handler invocation hook used for non-const function objects.
  58. template <typename Function>
  59. inline void asio_handler_invoke(Function& function, ...)
  60. {
  61. function();
  62. }
  63. /// Default handler invocation hook used for const function objects.
  64. template <typename Function>
  65. inline void asio_handler_invoke(const Function& function, ...)
  66. {
  67. Function tmp(function);
  68. tmp();
  69. }
  70. /*@}*/
  71. } // namespace asio
  72. #include "asio/detail/pop_options.hpp"
  73. #endif // ASIO_HANDLER_INVOKE_HOOK_HPP