// // detail/handler_work.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2018 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) // #ifndef BOOST_ASIO_DETAIL_HANDLER_WORK_HPP #define BOOST_ASIO_DETAIL_HANDLER_WORK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include namespace lslboost { namespace asio { namespace detail { // A helper class template to allow completion handlers to be dispatched // through either the new executors framework or the old invocaton hook. The // primary template uses the new executors framework. template ::type> class handler_work { public: explicit handler_work(Handler& handler) BOOST_ASIO_NOEXCEPT : executor_(associated_executor::get(handler)) { } static void start(Handler& handler) BOOST_ASIO_NOEXCEPT { Executor ex(associated_executor::get(handler)); ex.on_work_started(); } ~handler_work() { executor_.on_work_finished(); } template void complete(Function& function, Handler& handler) { executor_.dispatch(BOOST_ASIO_MOVE_CAST(Function)(function), associated_allocator::get(handler)); } private: // Disallow copying and assignment. handler_work(const handler_work&); handler_work& operator=(const handler_work&); typename associated_executor::type executor_; }; // This specialisation dispatches a handler through the old invocation hook. // The specialisation is not strictly required for correctness, as the // system_executor will dispatch through the hook anyway. However, by doing // this we avoid an extra copy of the handler. template class handler_work { public: explicit handler_work(Handler&) BOOST_ASIO_NOEXCEPT {} static void start(Handler&) BOOST_ASIO_NOEXCEPT {} ~handler_work() {} template void complete(Function& function, Handler& handler) { lslboost_asio_handler_invoke_helpers::invoke(function, handler); } private: // Disallow copying and assignment. handler_work(const handler_work&); handler_work& operator=(const handler_work&); }; } // namespace detail } // namespace asio } // namespace lslboost #include #endif // BOOST_ASIO_DETAIL_HANDLER_WORK_HPP