From: Max Kellermann Date: Tue, 8 Oct 2024 12:50:02 +0000 (+0200) Subject: msg/async/AsyncConnection: do not wrap writeCallback in `std::optional` X-Git-Tag: v20.0.0~792^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c72dae9b6e4b37c508a3ebb1410172fb7c434e8a;p=ceph.git msg/async/AsyncConnection: do not wrap writeCallback in `std::optional` Since `std::function` is nullable and as an `operator bool()`, we can easily eliminate the `std::optional` overhead. Signed-off-by: Max Kellermann --- diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 683be086efad..649977e5b969 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -621,7 +621,7 @@ void AsyncConnection::fault() } void AsyncConnection::_stop() { - writeCallback.reset(); + writeCallback = {}; dispatch_queue->discard_queue(conn_id); async_msgr->unregister_conn(this); worker->release_worker(); @@ -737,8 +737,7 @@ void AsyncConnection::handle_write_callback() { recv_start_time = ceph::mono_clock::now(); write_lock.lock(); if (writeCallback) { - auto callback = *writeCallback; - writeCallback.reset(); + auto callback = std::move(writeCallback); write_lock.unlock(); callback(0); return; diff --git a/src/msg/async/AsyncConnection.h b/src/msg/async/AsyncConnection.h index 78a590f8ca39..a4f18e2c4fb5 100644 --- a/src/msg/async/AsyncConnection.h +++ b/src/msg/async/AsyncConnection.h @@ -223,7 +223,7 @@ private: std::unique_ptr protocol; - std::optional> writeCallback; + std::function writeCallback; std::function readCallback; std::optional pendingReadLen; char *read_buffer; diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index cecf81498c70..a53f6389c310 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -1294,7 +1294,7 @@ void ProtocolV1::reset_recv_state() // clean read and write callbacks connection->pendingReadLen.reset(); - connection->writeCallback.reset(); + connection->writeCallback = {}; if (state > THROTTLE_MESSAGE && state <= READ_FOOTER_AND_DISPATCH && connection->policy.throttler_messages) { diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index 11b3885a2240..79fdf6c30a36 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -266,7 +266,7 @@ void ProtocolV2::reset_recv_state() { // clean read and write callbacks connection->pendingReadLen.reset(); - connection->writeCallback.reset(); + connection->writeCallback = {}; next_tag = static_cast(0);