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

	* thread-pool.cc (thread_pool::post_task): Update.
	* thread-pool.h (class thread_pool) <post_task>: Take rvalue
	reference to function.
This commit is contained in:
Tom Tromey 2021-04-30 10:04:56 -06:00
parent 2869ac4b59
commit 698facb837
3 changed files with 9 additions and 3 deletions

View 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>

View 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)

View 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: