From 698facb837c556b0e189b92563ec8bd4f2de373d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 30 Apr 2021 10:04:56 -0600 Subject: [PATCH] Use rvalue reference in thread_pool::post_task Tankut's recent patches made me realize that thread_pool::post_task should have used an rvalue reference for its parameter. This patch makes this change. gdbsupport/ChangeLog 2021-04-30 Tom Tromey * thread-pool.cc (thread_pool::post_task): Update. * thread-pool.h (class thread_pool) : Take rvalue reference to function. --- gdbsupport/ChangeLog | 6 ++++++ gdbsupport/thread-pool.cc | 4 ++-- gdbsupport/thread-pool.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 2b575ea3118..72802c66c56 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,9 @@ +2021-04-30 Tom Tromey + + * thread-pool.cc (thread_pool::post_task): Update. + * thread-pool.h (class thread_pool) : Take rvalue + reference to function. + 2021-04-27 Michael Weghorn Simon Marchi diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc index cd5e11673a9..2bb75cc9cef 100644 --- a/gdbsupport/thread-pool.cc +++ b/gdbsupport/thread-pool.cc @@ -130,9 +130,9 @@ thread_pool::set_thread_count (size_t num_threads) } std::future -thread_pool::post_task (std::function func) +thread_pool::post_task (std::function &&func) { - std::packaged_task t (func); + std::packaged_task t (std::move (func)); std::future f = t.get_future (); if (m_thread_count == 0) diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h index b28b74647c5..9bddaa9eaae 100644 --- a/gdbsupport/thread-pool.h +++ b/gdbsupport/thread-pool.h @@ -58,7 +58,7 @@ public: /* Post a task to the thread pool. A future is returned, which can be used to wait for the result. */ - std::future post_task (std::function func); + std::future post_task (std::function &&func); private: -- 2.30.2