diff options
Diffstat (limited to '3rdparty/asio/include/asio/io_context_strand.hpp')
-rw-r--r-- | 3rdparty/asio/include/asio/io_context_strand.hpp | 156 |
1 files changed, 85 insertions, 71 deletions
diff --git a/3rdparty/asio/include/asio/io_context_strand.hpp b/3rdparty/asio/include/asio/io_context_strand.hpp index 53a6c4690c2..288ac238feb 100644 --- a/3rdparty/asio/include/asio/io_context_strand.hpp +++ b/3rdparty/asio/include/asio/io_context_strand.hpp @@ -2,7 +2,7 @@ // io_context_strand.hpp // ~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -17,7 +17,8 @@ #include "asio/detail/config.hpp" -#if !defined(ASIO_NO_EXTENSIONS) +#if !defined(ASIO_NO_EXTENSIONS) \ + && !defined(ASIO_NO_TS_EXECUTORS) #include "asio/async_result.hpp" #include "asio/detail/handler_type_requirements.hpp" @@ -63,8 +64,7 @@ namespace asio { * @li @c s.dispatch(a) happens-before @c s.dispatch(b), where both are * performed outside the strand * - * then @c asio_handler_invoke(a1, &a1) happens-before - * @c asio_handler_invoke(b1, &b1). + * then @c a() happens-before @c b() * * Note that in the following case: * @code async_op_1(..., s.wrap(a)); @@ -87,6 +87,12 @@ namespace asio { */ class io_context::strand { +private: +#if !defined(ASIO_NO_DEPRECATED) + struct initiate_dispatch; + struct initiate_post; +#endif // !defined(ASIO_NO_DEPRECATED) + public: /// Constructor. /** @@ -102,49 +108,30 @@ public: service_.construct(impl_); } - /// Destructor. + /// Copy constructor. /** - * Destroys a strand. - * - * Handlers posted through the strand that have not yet been invoked will - * still be dispatched in a way that meets the guarantee of non-concurrency. - */ - ~strand() - { - } - -#if !defined(ASIO_NO_DEPRECATED) - /// (Deprecated: Use context().) Get the io_context associated with the - /// strand. - /** - * This function may be used to obtain the io_context object that the strand - * uses to dispatch handlers for asynchronous operations. - * - * @return A reference to the io_context object that the strand will use to - * dispatch handlers. Ownership is not transferred to the caller. + * Creates a copy such that both strand objects share the same underlying + * state. */ - asio::io_context& get_io_context() + strand(const strand& other) noexcept + : service_(other.service_), + impl_(other.impl_) { - return service_.get_io_context(); } - /// (Deprecated: Use context().) Get the io_context associated with the - /// strand. + /// Destructor. /** - * This function may be used to obtain the io_context object that the strand - * uses to dispatch handlers for asynchronous operations. + * Destroys a strand. * - * @return A reference to the io_context object that the strand will use to - * dispatch handlers. Ownership is not transferred to the caller. + * Handlers posted through the strand that have not yet been invoked will + * still be dispatched in a way that meets the guarantee of non-concurrency. */ - asio::io_context& get_io_service() + ~strand() { - return service_.get_io_context(); } -#endif // !defined(ASIO_NO_DEPRECATED) /// Obtain the underlying execution context. - asio::io_context& context() ASIO_NOEXCEPT + asio::io_context& context() const noexcept { return service_.get_io_context(); } @@ -153,7 +140,7 @@ public: /** * The strand delegates this call to its underlying io_context. */ - void on_work_started() ASIO_NOEXCEPT + void on_work_started() const noexcept { context().get_executor().on_work_started(); } @@ -162,7 +149,7 @@ public: /** * The strand delegates this call to its underlying io_context. */ - void on_work_finished() ASIO_NOEXCEPT + void on_work_finished() const noexcept { context().get_executor().on_work_finished(); } @@ -183,9 +170,9 @@ public: * internal storage needed for function invocation. */ template <typename Function, typename Allocator> - void dispatch(ASIO_MOVE_ARG(Function) f, const Allocator& a) + void dispatch(Function&& f, const Allocator& a) const { - typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f)); + decay_t<Function> tmp(static_cast<Function&&>(f)); service_.dispatch(impl_, tmp); (void)a; } @@ -211,19 +198,14 @@ public: * handler object as required. The function signature of the handler must be: * @code void handler(); @endcode */ - template <typename CompletionHandler> - ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) - dispatch(ASIO_MOVE_ARG(CompletionHandler) handler) + template <typename LegacyCompletionHandler> + auto dispatch(LegacyCompletionHandler&& handler) + -> decltype( + async_initiate<LegacyCompletionHandler, void ()>( + declval<initiate_dispatch>(), handler, this)) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a CompletionHandler. - ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - - async_completion<CompletionHandler, void ()> init(handler); - - service_.dispatch(impl_, init.completion_handler); - - return init.result.get(); + return async_initiate<LegacyCompletionHandler, void ()>( + initiate_dispatch(), handler, this); } #endif // !defined(ASIO_NO_DEPRECATED) @@ -241,9 +223,9 @@ public: * internal storage needed for function invocation. */ template <typename Function, typename Allocator> - void post(ASIO_MOVE_ARG(Function) f, const Allocator& a) + void post(Function&& f, const Allocator& a) const { - typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f)); + decay_t<Function> tmp(static_cast<Function&&>(f)); service_.post(impl_, tmp); (void)a; } @@ -265,19 +247,14 @@ public: * handler object as required. The function signature of the handler must be: * @code void handler(); @endcode */ - template <typename CompletionHandler> - ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) - post(ASIO_MOVE_ARG(CompletionHandler) handler) + template <typename LegacyCompletionHandler> + auto post(LegacyCompletionHandler&& handler) + -> decltype( + async_initiate<LegacyCompletionHandler, void ()>( + declval<initiate_post>(), handler, this)) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a CompletionHandler. - ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - - async_completion<CompletionHandler, void ()> init(handler); - - service_.post(impl_, init.completion_handler); - - return init.result.get(); + return async_initiate<LegacyCompletionHandler, void ()>( + initiate_post(), handler, this); } #endif // !defined(ASIO_NO_DEPRECATED) @@ -295,9 +272,9 @@ public: * internal storage needed for function invocation. */ template <typename Function, typename Allocator> - void defer(ASIO_MOVE_ARG(Function) f, const Allocator& a) + void defer(Function&& f, const Allocator& a) const { - typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f)); + decay_t<Function> tmp(static_cast<Function&&>(f)); service_.post(impl_, tmp); (void)a; } @@ -343,7 +320,7 @@ public: * submitted to the strand using post(), dispatch() or wrap(). Otherwise * returns @c false. */ - bool running_in_this_thread() const ASIO_NOEXCEPT + bool running_in_this_thread() const noexcept { return service_.running_in_this_thread(impl_); } @@ -353,7 +330,7 @@ public: * Two strands are equal if they refer to the same ordered, non-concurrent * state. */ - friend bool operator==(const strand& a, const strand& b) ASIO_NOEXCEPT + friend bool operator==(const strand& a, const strand& b) noexcept { return a.impl_ == b.impl_; } @@ -363,14 +340,50 @@ public: * Two strands are equal if they refer to the same ordered, non-concurrent * state. */ - friend bool operator!=(const strand& a, const strand& b) ASIO_NOEXCEPT + friend bool operator!=(const strand& a, const strand& b) noexcept { return a.impl_ != b.impl_; } private: +#if !defined(ASIO_NO_DEPRECATED) + struct initiate_dispatch + { + template <typename LegacyCompletionHandler> + void operator()(LegacyCompletionHandler&& handler, + strand* self) const + { + // If you get an error on the following line it means that your + // handler does not meet the documented type requirements for a + // LegacyCompletionHandler. + ASIO_LEGACY_COMPLETION_HANDLER_CHECK( + LegacyCompletionHandler, handler) type_check; + + detail::non_const_lvalue<LegacyCompletionHandler> handler2(handler); + self->service_.dispatch(self->impl_, handler2.value); + } + }; + + struct initiate_post + { + template <typename LegacyCompletionHandler> + void operator()(LegacyCompletionHandler&& handler, + strand* self) const + { + // If you get an error on the following line it means that your + // handler does not meet the documented type requirements for a + // LegacyCompletionHandler. + ASIO_LEGACY_COMPLETION_HANDLER_CHECK( + LegacyCompletionHandler, handler) type_check; + + detail::non_const_lvalue<LegacyCompletionHandler> handler2(handler); + self->service_.post(self->impl_, handler2.value); + } + }; +#endif // !defined(ASIO_NO_DEPRECATED) + asio::detail::strand_service& service_; - asio::detail::strand_service::implementation_type impl_; + mutable asio::detail::strand_service::implementation_type impl_; }; } // namespace asio @@ -378,5 +391,6 @@ private: #include "asio/detail/pop_options.hpp" #endif // !defined(ASIO_NO_EXTENSIONS) + // && !defined(ASIO_NO_TS_EXECUTORS) #endif // ASIO_IO_CONTEXT_STRAND_HPP |