From: Casey Bodley Date: Mon, 14 Oct 2024 18:25:19 +0000 (-0400) Subject: common/async: SharedMutex uses append instead of bind_handler X-Git-Tag: v20.0.0~574^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=abaca8110ad40efa2007d365e53f109791b421f1;p=ceph.git common/async: SharedMutex uses append instead of bind_handler boost::asio::append() is the modern way to bind additional values to the completion handler while preserving its associated executor, allocator, cancellation slot, etc this obviates the need for bind_handler() itself, but its template class CompletionHandler is still useful if we're already storing the arguments in a std::tuple<> like CompletionImpl::bind_and_forward() Signed-off-by: Casey Bodley --- diff --git a/src/common/async/detail/shared_mutex.h b/src/common/async/detail/shared_mutex.h index 6eae25b430d8..db7890049abe 100644 --- a/src/common/async/detail/shared_mutex.h +++ b/src/common/async/detail/shared_mutex.h @@ -19,6 +19,7 @@ #include #include // for std::shared_lock +#include #include #include #include @@ -134,10 +135,8 @@ auto SharedMutexImpl::async_lock(Mutex& mtx, CompletionToken&& token) state = Exclusive; // post a successful completion - auto ex2 = boost::asio::get_associated_executor(handler, ex1); - auto h = boost::asio::bind_executor(ex2, std::move(handler)); - boost::asio::post(bind_handler(std::move(h), ec, - std::unique_lock{mtx, std::adopt_lock})); + boost::asio::post(ex1, boost::asio::append(std::move(handler), + ec, std::unique_lock{mtx, std::adopt_lock})); } else { // create a request and add it to the exclusive list using LockCompletion = typename Request::LockCompletion; @@ -224,10 +223,8 @@ auto SharedMutexImpl::async_lock_shared(Mutex& mtx, CompletionToken&& token) if (exclusive_queue.empty() && state < MaxShared) { state++; - auto ex2 = boost::asio::get_associated_executor(handler, ex1); - auto h = boost::asio::bind_executor(ex2, std::move(handler)); - boost::asio::post(bind_handler(std::move(h), ec, - std::shared_lock{mtx, std::adopt_lock})); + boost::asio::post(ex1, boost::asio::append(std::move(handler), + ec, std::shared_lock{mtx, std::adopt_lock})); } else { using LockCompletion = typename Request::LockCompletion; auto request = LockCompletion::create(ex1, std::move(handler), mtx);