From: Adam C. Emerson Date: Fri, 21 Feb 2020 17:46:47 +0000 (-0500) Subject: common: bind_like X-Git-Tag: v16.1.0~1154^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fba1845211064a9b6121127b636d38fb50924853;p=ceph.git common: bind_like A template to ensure that one completion has the same executor and allocator as another. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/async/bind_like.h b/src/common/async/bind_like.h new file mode 100644 index 000000000000..a7fdbb869c9e --- /dev/null +++ b/src/common/async/bind_like.h @@ -0,0 +1,40 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 Red Hat + * Author: Adam C. Emerson + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include +#include + +#include "common/async/bind_allocator.h" + +namespace ceph::async { +template +auto bind_ea(const Executor& executor, const Allocator& allocator, + Completion&& completion) { + return bind_allocator(allocator, + boost::asio::bind_executor( + executor, + std::forward(completion))); +} + + +// Bind `Completion` to the executor and allocator of `Proto` +template +auto bind_like(const Proto& proto, Completion&& completion) { + return bind_ea(boost::asio::get_associated_executor(proto), + boost::asio::get_associated_allocator(proto), + std::forward(completion)); +} +}