Skip to content

Commit abaca81

Browse files
committed
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 <[email protected]>
1 parent 56e48d4 commit abaca81

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/common/async/detail/shared_mutex.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <optional>
2020
#include <shared_mutex> // for std::shared_lock
2121

22+
#include <boost/asio/append.hpp>
2223
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
2324
#include <boost/intrusive_ptr.hpp>
2425
#include <boost/intrusive/list.hpp>
@@ -134,10 +135,8 @@ auto SharedMutexImpl::async_lock(Mutex& mtx, CompletionToken&& token)
134135
state = Exclusive;
135136

136137
// post a successful completion
137-
auto ex2 = boost::asio::get_associated_executor(handler, ex1);
138-
auto h = boost::asio::bind_executor(ex2, std::move(handler));
139-
boost::asio::post(bind_handler(std::move(h), ec,
140-
std::unique_lock{mtx, std::adopt_lock}));
138+
boost::asio::post(ex1, boost::asio::append(std::move(handler),
139+
ec, std::unique_lock{mtx, std::adopt_lock}));
141140
} else {
142141
// create a request and add it to the exclusive list
143142
using LockCompletion = typename Request::LockCompletion;
@@ -224,10 +223,8 @@ auto SharedMutexImpl::async_lock_shared(Mutex& mtx, CompletionToken&& token)
224223
if (exclusive_queue.empty() && state < MaxShared) {
225224
state++;
226225

227-
auto ex2 = boost::asio::get_associated_executor(handler, ex1);
228-
auto h = boost::asio::bind_executor(ex2, std::move(handler));
229-
boost::asio::post(bind_handler(std::move(h), ec,
230-
std::shared_lock{mtx, std::adopt_lock}));
226+
boost::asio::post(ex1, boost::asio::append(std::move(handler),
227+
ec, std::shared_lock{mtx, std::adopt_lock}));
231228
} else {
232229
using LockCompletion = typename Request::LockCompletion;
233230
auto request = LockCompletion::create(ex1, std::move(handler), mtx);

0 commit comments

Comments
 (0)