[PATCH] Use rvalue reference in thread_pool::post_task

Tom Tromey tromey@adacore.com
Wed Apr 21 19:49:06 GMT 2021


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-21  Tom Tromey  <tromey@adacore.com>

	* thread-pool.cc (thread_pool::post_task): Update.
	* thread-pool.h (class thread_pool) <post_task>: 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/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<void>
-thread_pool::post_task (std::function<void ()> func)
+thread_pool::post_task (std::function<void ()> &&func)
 {
-  std::packaged_task<void ()> t (func);
+  std::packaged_task<void ()> t (std::move (func));
   std::future<void> 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 @@ class thread_pool
 
   /* Post a task to the thread pool.  A future is returned, which can
      be used to wait for the result.  */
-  std::future<void> post_task (std::function<void ()> func);
+  std::future<void> post_task (std::function<void ()> &&func);
 
 private:
 
-- 
2.26.2



More information about the Gdb-patches mailing list