]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/async: SharedMutex uses append instead of bind_handler
authorCasey Bodley <cbodley@redhat.com>
Mon, 14 Oct 2024 18:25:19 +0000 (14:25 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 15 Oct 2024 01:59:13 +0000 (21:59 -0400)
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 <cbodley@redhat.com>
src/common/async/detail/shared_mutex.h

index 6eae25b430d860b0f1e3a9ab031db85e9f7e19fd..db7890049abea14217d1be8945133f2ad53b302f 100644 (file)
@@ -19,6 +19,7 @@
 #include <optional>
 #include <shared_mutex> // for std::shared_lock
 
+#include <boost/asio/append.hpp>
 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
 #include <boost/intrusive_ptr.hpp>
 #include <boost/intrusive/list.hpp>
@@ -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);