From e076245b70b311544326f3cc252f50227753820b Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Mon, 7 Nov 2016 16:24:58 -0500 Subject: [PATCH] async: Do not use std::move on temporaries 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 --- src/msg/async/Stack.cc | 15 ++++++--------- src/msg/async/Stack.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/msg/async/Stack.cc b/src/msg/async/Stack.cc index e60f040b059ef..d0c735b3aeeb3 100644 --- a/src/msg/async/Stack.cc +++ b/src/msg/async/Stack.cc @@ -31,13 +31,12 @@ #undef dout_prefix #define dout_prefix *_dout << "stack " -void NetworkStack::add_thread(unsigned i, std::function &thread) +std::function 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 &thread) } w->reset(); w->destroy(); - } - ); + }; } std::shared_ptr 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 thread; - add_thread(i, thread); + std::function thread = add_thread(i); spawn_worker(i, std::move(thread)); } started = true; diff --git a/src/msg/async/Stack.h b/src/msg/async/Stack.h index 2f16ca8831518..b1cb5c3cf5da3 100644 --- a/src/msg/async/Stack.h +++ b/src/msg/async/Stack.h @@ -281,7 +281,7 @@ class NetworkStack : public CephContext::ForkWatcher { Spinlock pool_spin; bool started = false; - void add_thread(unsigned i, std::function &ts); + std::function add_thread(unsigned i); protected: CephContext *cct; -- 2.39.5