]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
async: Do not use std::move on temporaries
authorAdam C. Emerson <aemerson@redhat.com>
Mon, 7 Nov 2016 21:24:58 +0000 (16:24 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 17 Nov 2016 00:54:31 +0000 (19:54 -0500)
It can actually cause the compiler to copy where it wouldn't
otherwise. Just return the std::function and take advantage of RVO.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/msg/async/Stack.cc
src/msg/async/Stack.h

index e60f040b059efe9240812f5e1ea8fe10c744cf98..d0c735b3aeeb3beb7efed89425c9ac30e8511258 100644 (file)
 #undef dout_prefix
 #define dout_prefix *_dout << "stack "
 
-void NetworkStack::add_thread(unsigned i, std::function<void ()> &thread)
+std::function<void ()> NetworkStack::add_thread(unsigned i)
 {
   Worker *w = workers[i];
-  thread = std::move(
-    [this, w]() {
-      const uint64_t EventMaxWaitUs = 30000000;
-      w->center.set_owner();
+  return [this, w]() {
+    const uint64_t EventMaxWaitUs = 30000000;
+    w->center.set_owner();
       ldout(cct, 10) << __func__ << " starting" << dendl;
       w->initialize();
       w->init_done();
@@ -53,8 +52,7 @@ void NetworkStack::add_thread(unsigned i, std::function<void ()> &thread)
       }
       w->reset();
       w->destroy();
-    }
-  );
+  };
 }
 
 std::shared_ptr<NetworkStack> NetworkStack::create(CephContext *c, const string &t)
@@ -119,8 +117,7 @@ void NetworkStack::start()
   for (unsigned i = 0; i < num_workers; ++i) {
     if (workers[i]->is_init())
       continue;
-    std::function<void ()> thread;
-    add_thread(i, thread);
+    std::function<void ()> thread = add_thread(i);
     spawn_worker(i, std::move(thread));
   }
   started = true;
index 2f16ca883151864568b38e7c2f6406dc9bb15385..b1cb5c3cf5da32e1fcd0bdbb6e23c8d38b8189ed 100644 (file)
@@ -281,7 +281,7 @@ class NetworkStack : public CephContext::ForkWatcher {
   Spinlock pool_spin;
   bool started = false;
 
-  void add_thread(unsigned i, std::function<void ()> &ts);
+  std::function<void ()> add_thread(unsigned i);
 
  protected:
   CephContext *cct;