Skip to content

Commit 698facb

Browse files
committed
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 <[email protected]> * thread-pool.cc (thread_pool::post_task): Update. * thread-pool.h (class thread_pool) <post_task>: Take rvalue reference to function.
1 parent 2869ac4 commit 698facb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

gdbsupport/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2021-04-30 Tom Tromey <[email protected]>
2+
3+
* thread-pool.cc (thread_pool::post_task): Update.
4+
* thread-pool.h (class thread_pool) <post_task>: Take rvalue
5+
reference to function.
6+
17
2021-04-27 Michael Weghorn <[email protected]>
28
Simon Marchi <[email protected]>
39

gdbsupport/thread-pool.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ thread_pool::set_thread_count (size_t num_threads)
130130
}
131131

132132
std::future<void>
133-
thread_pool::post_task (std::function<void ()> func)
133+
thread_pool::post_task (std::function<void ()> &&func)
134134
{
135-
std::packaged_task<void ()> t (func);
135+
std::packaged_task<void ()> t (std::move (func));
136136
std::future<void> f = t.get_future ();
137137

138138
if (m_thread_count == 0)

gdbsupport/thread-pool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class thread_pool
5858

5959
/* Post a task to the thread pool. A future is returned, which can
6060
be used to wait for the result. */
61-
std::future<void> post_task (std::function<void ()> func);
61+
std::future<void> post_task (std::function<void ()> &&func);
6262

6363
private:
6464

0 commit comments

Comments
 (0)