New move support for strand. Note that some copies are unavoidable.
This commit is contained in:
parent
021738d19c
commit
a0bbf61bf0
@ -36,6 +36,20 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
wrapped_handler(const wrapped_handler& other)
|
||||
: dispatcher_(other.dispatcher_),
|
||||
handler_(other.handler_)
|
||||
{
|
||||
}
|
||||
|
||||
wrapped_handler(wrapped_handler&& other)
|
||||
: dispatcher_(other.dispatcher_),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
dispatcher_.dispatch(handler_);
|
||||
@ -125,12 +139,32 @@ template <typename Handler, typename Context>
|
||||
class rewrapped_handler
|
||||
{
|
||||
public:
|
||||
explicit rewrapped_handler(const Handler& handler, const Context& context)
|
||||
: handler_(handler),
|
||||
context_(context)
|
||||
explicit rewrapped_handler(Handler& handler, const Context& context)
|
||||
: context_(context),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
explicit rewrapped_handler(const Handler& handler, const Context& context)
|
||||
: context_(context),
|
||||
handler_(handler)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
rewrapped_handler(const rewrapped_handler& other)
|
||||
: context_(other.context_),
|
||||
handler_(other.handler_)
|
||||
{
|
||||
}
|
||||
|
||||
rewrapped_handler(rewrapped_handler&& other)
|
||||
: context_(ASIO_MOVE_CAST(Context)(other.context_)),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_();
|
||||
@ -142,8 +176,8 @@ public:
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Context context_;
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <typename Dispatcher, typename Handler>
|
||||
@ -162,6 +196,15 @@ inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Dispatcher, typename Handler>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
wrapped_handler<Dispatcher, Handler>* this_handler)
|
||||
{
|
||||
this_handler->dispatcher_.dispatch(
|
||||
rewrapped_handler<Function, Handler>(
|
||||
function, this_handler->handler_));
|
||||
}
|
||||
|
||||
template <typename Function, typename Dispatcher, typename Handler>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
wrapped_handler<Dispatcher, Handler>* this_handler)
|
||||
@ -187,6 +230,14 @@ inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
pointer, size, this_handler->context_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Context>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
rewrapped_handler<Handler, Context>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->context_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Context>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
rewrapped_handler<Handler, Context>* this_handler)
|
||||
|
@ -140,13 +140,13 @@ public:
|
||||
* @code void handler(); @endcode
|
||||
*/
|
||||
template <typename CompletionHandler>
|
||||
void dispatch(CompletionHandler handler)
|
||||
void dispatch(ASIO_MOVE_ARG(CompletionHandler) handler)
|
||||
{
|
||||
// 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;
|
||||
|
||||
service_.dispatch(impl_, handler);
|
||||
service_.dispatch(impl_, ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
/// Request the strand to invoke the given handler and return
|
||||
@ -166,13 +166,13 @@ public:
|
||||
* @code void handler(); @endcode
|
||||
*/
|
||||
template <typename CompletionHandler>
|
||||
void post(CompletionHandler handler)
|
||||
void post(ASIO_MOVE_ARG(CompletionHandler) handler)
|
||||
{
|
||||
// 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;
|
||||
|
||||
service_.post(impl_, handler);
|
||||
service_.post(impl_, ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
/// Create a new handler that automatically dispatches the wrapped handler
|
||||
|
Loading…
Reference in New Issue
Block a user