Use rvalue reference in thread_pool::post_task
authorTom Tromey <tromey@adacore.com>
Fri, 30 Apr 2021 16:04:56 +0000 (10:04 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 30 Apr 2021 16:04:56 +0000 (10:04 -0600)
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  <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
gdbsupport/thread-pool.cc
gdbsupport/thread-pool.h

index 2b575ea3118f4a77b934909e589421088a3e61bd..72802c66c56d83a8776148020debf4d9c29dda62 100644 (file)
@@ -1,3 +1,9 @@
+2021-04-30  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.
+
 2021-04-27  Michael Weghorn  <m.weghorn@posteo.de>
            Simon Marchi  <simon.marchi@polymtl.ca>
 
index cd5e11673a925d408ab9e92afa833e277f629538..2bb75cc9cef4b6ab42e0779106063aa9e53fb38a 100644 (file)
@@ -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)
index b28b74647c5fe141aeb1b4744224bc44f11057c9..9bddaa9eaaed05331e5b16a3eaf5b893859b73b4 100644 (file)
@@ -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<void> post_task (std::function<void ()> func);
+  std::future<void> post_task (std::function<void ()> &&func);
 
 private:
 
This page took 0.024715 seconds and 4 git commands to generate.