]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg/async/AsyncConnection: do not wrap writeCallback in `std::optional`
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 8 Oct 2024 12:50:02 +0000 (14:50 +0200)
committerPatrick Donnelly <pdonnell@ibm.com>
Mon, 13 Oct 2025 23:59:06 +0000 (19:59 -0400)
Since `std::function` is nullable and as an `operator bool()`, we can
easily eliminate the `std::optional` overhead.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
(cherry picked from commit c72dae9b6e4b37c508a3ebb1410172fb7c434e8a)

src/msg/async/AsyncConnection.cc
src/msg/async/AsyncConnection.h
src/msg/async/ProtocolV1.cc
src/msg/async/ProtocolV2.cc

index 683be086efadad84a9221d45e31ba2dbed2bdc43..649977e5b9697fd7861f081a3f2bd65df1db49d2 100644 (file)
@@ -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;
index 78a590f8ca393eaef103cf4303d19373a2febfce..a4f18e2c4fb5702d0c60abecf2364de0a7c39243 100644 (file)
@@ -223,7 +223,7 @@ private:
 
   std::unique_ptr<Protocol> protocol;
 
-  std::optional<std::function<void(ssize_t)>> writeCallback;
+  std::function<void(ssize_t)> writeCallback;
   std::function<void(char *, ssize_t)> readCallback;
   std::optional<unsigned> pendingReadLen;
   char *read_buffer;
index c0eeae5f674187bd293c3705b862f69f1b3705c1..7621af1fbab235bd12fa2a91f6b93a05d7f1fd12 100644 (file)
@@ -1293,7 +1293,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) {
index 322346a64a23bb1a0fc9af7f493f56e4cace107c..137d78872ac6b51b19d554d9feb50f8f434e89ff 100644 (file)
@@ -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<Tag>(0);