diff options
author | Christian Biesinger <cbiesinger@google.com> | 2019-10-08 17:25:26 -0500 |
---|---|---|
committer | Christian Biesinger <cbiesinger@google.com> | 2019-10-08 17:36:15 -0500 |
commit | d13d16c4d8e976ebd00353e04ca8a761b8850a11 (patch) | |
tree | c5934e66287c895b75dddf3a29945797f1160193 /gdb/gdbsupport/thread_pool.h | |
parent | 52300df201ed1a35eb15b2bc5eb441a1b7eec393 (diff) | |
download | gdb-users/cbiesinger/threadpool.zip gdb-users/cbiesinger/threadpool.tar.gz gdb-users/cbiesinger/threadpool.tar.bz2 |
Switch to futuresusers/cbiesinger/threadpool
Diffstat (limited to 'gdb/gdbsupport/thread_pool.h')
-rw-r--r-- | gdb/gdbsupport/thread_pool.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gdb/gdbsupport/thread_pool.h b/gdb/gdbsupport/thread_pool.h index 77760a9..9717263 100644 --- a/gdb/gdbsupport/thread_pool.h +++ b/gdb/gdbsupport/thread_pool.h @@ -8,6 +8,7 @@ #include <atomic> #include <mutex> #include <condition_variable> +#include <future> namespace gdb { @@ -20,11 +21,14 @@ class thread_pool { void start(size_t num_threads); - typedef std::function<void ()> task; - void post_task(task t) { + typedef std::packaged_task<void()> task; + std::future<void> post_task(std::function<void ()> func) { + task t(func); + std::future<void> f = t.get_future(); std::lock_guard<std::mutex> guard (m_tasks_mutex); - m_tasks.push (t); + m_tasks.push (std::move (t)); m_tasks_cv.notify_one (); + return f; } private: |