6#include <unordered_set>
30 std::lock_guard<std::mutex> lock(m_futures_mutex);
32 typedef typename std::invoke_result<F>::type result_type;
34 std::shared_ptr<std::packaged_task<result_type()>> task_ptr = std::make_shared<std::packaged_task<result_type()>>(std::move(f));
37 uint64_t
id = m_counter++;
38 std::function<void()> wrapper_func = [task_ptr = std::move(task_ptr),
this, id] ()
mutable
40 std::exception_ptr eptr =
nullptr;
41 auto future = task_ptr->get_future();
50 eptr = std::current_exception();
54 std::lock_guard<std::mutex> lock(m_finished_tasks_mutex);
55 m_finished_tasks.insert(
id);
59 std::rethrow_exception(eptr);
63 std::future<void> future_v = m_executor.
run(wrapper_func);
64 m_futures.insert(std::make_pair(
id, std::move(future_v)));
94 uint64_t m_counter = 0;
96 std::unordered_set<uint64_t> m_finished_tasks;
97 std::mutex m_finished_tasks_mutex;
98 std::unordered_map<uint64_t, std::future<void>> m_futures;
99 std::mutex m_futures_mutex;
107 void waitTask(uint64_t
id);
Definition: ExecutorAccessor.hpp:10
uint64_t submit(F &&f)
Submit a task to the threadpool, the task will be executed asynchronously.
Definition: ExecutorAccessor.hpp:28
ExecutorAccessor(ExecutorAccessor &&)=delete
ExecutorAccessor()
Definition: ExecutorAccessor.cpp:3
ExecutorAccessor & operator=(ExecutorAccessor &&)=delete
ExecutorAccessor & operator=(const ExecutorAccessor &)=delete
void waitForFinishedTasks()
wait for all finished task
Definition: ExecutorAccessor.cpp:22
ExecutorAccessor(const ExecutorAccessor &)=delete
void waitForAll()
wait for all tasks to finish
Definition: ExecutorAccessor.cpp:13
void waitForTask(uint64_t id)
wait for a specific task to finish
Definition: ExecutorAccessor.cpp:37
~ExecutorAccessor()
Definition: ExecutorAccessor.cpp:8
void waitForTasks(const std::vector< uint64_t > &ids)
wait for a list of tasks to finish
Definition: ExecutorAccessor.cpp:43
Definition: Executor.hpp:21
std::future< void > run(std::shared_ptr< TaskGraph > graph)
Definition: Executor.cpp:33