Repository: kudu Updated Branches: refs/heads/master ddb2c16bf -> eaf108a65
threadpool: use move semantics where possible This uses std::move() where possible to avoid extra copies or reference counting overhead in the ThreadPool code. Change-Id: I180154bd7fd9ecd40188490db0b60ae8e58e554f Reviewed-on: http://gerrit.cloudera.org:8080/5518 Tested-by: Kudu Jenkins Reviewed-by: Mike Percy <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/eaf108a6 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/eaf108a6 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/eaf108a6 Branch: refs/heads/master Commit: eaf108a65425da5c8bd573c2442a6dd6f82143e2 Parents: ddb2c16 Author: Todd Lipcon <[email protected]> Authored: Thu Dec 15 17:44:25 2016 +0700 Committer: Mike Percy <[email protected]> Committed: Wed Jan 4 01:15:05 2017 +0000 ---------------------------------------------------------------------- src/kudu/util/threadpool.cc | 10 +++++----- src/kudu/util/threadpool.h | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/eaf108a6/src/kudu/util/threadpool.cc ---------------------------------------------------------------------- diff --git a/src/kudu/util/threadpool.cc b/src/kudu/util/threadpool.cc index 9ad1cba..b3f4ddf 100644 --- a/src/kudu/util/threadpool.cc +++ b/src/kudu/util/threadpool.cc @@ -182,11 +182,11 @@ Status ThreadPool::SubmitClosure(const Closure& task) { return SubmitFunc(boost::bind(&Closure::Run, task)); } -Status ThreadPool::SubmitFunc(const boost::function<void()>& func) { - return Submit(std::shared_ptr<Runnable>(new FunctionRunnable(func))); +Status ThreadPool::SubmitFunc(boost::function<void()> func) { + return Submit(std::shared_ptr<Runnable>(new FunctionRunnable(std::move(func)))); } -Status ThreadPool::Submit(const std::shared_ptr<Runnable>& task) { +Status ThreadPool::Submit(std::shared_ptr<Runnable> task) { MonoTime submit_time = MonoTime::Now(); MutexLock guard(lock_); @@ -229,7 +229,7 @@ Status ThreadPool::Submit(const std::shared_ptr<Runnable>& task) { } QueueEntry e; - e.runnable = task; + e.runnable = std::move(task); e.trace = Trace::CurrentTrace(); // Need to AddRef, since the thread which submitted the task may go away, // and we don't want the trace to be destructed while waiting in the queue. @@ -238,7 +238,7 @@ Status ThreadPool::Submit(const std::shared_ptr<Runnable>& task) { } e.submit_time = submit_time; - queue_.push_back(e); + queue_.emplace_back(std::move(e)); int length_at_submit = queue_size_++; guard.Unlock(); http://git-wip-us.apache.org/repos/asf/kudu/blob/eaf108a6/src/kudu/util/threadpool.h ---------------------------------------------------------------------- diff --git a/src/kudu/util/threadpool.h b/src/kudu/util/threadpool.h index 0bbce7d..7dc0187 100644 --- a/src/kudu/util/threadpool.h +++ b/src/kudu/util/threadpool.h @@ -157,12 +157,10 @@ class ThreadPool { Status SubmitClosure(const Closure& task) WARN_UNUSED_RESULT; // Submit a function binded using boost::bind(&FuncName, args...) - Status SubmitFunc(const boost::function<void()>& func) - WARN_UNUSED_RESULT; + Status SubmitFunc(boost::function<void()> func) WARN_UNUSED_RESULT; // Submit a Runnable class - Status Submit(const std::shared_ptr<Runnable>& task) - WARN_UNUSED_RESULT; + Status Submit(std::shared_ptr<Runnable> task) WARN_UNUSED_RESULT; // Wait until all the tasks are completed. void Wait();
