1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Code cleanup, add comments where relevant

This commit is contained in:
Ivan Savenko
2025-03-12 15:57:06 +00:00
parent 6877bbfe3a
commit ed4079e83b
4 changed files with 21 additions and 15 deletions

View File

@@ -9,23 +9,27 @@
*/
#pragma once
#include <tbb/task_group.h>
#include <tbb/task_arena.h>
#include <tbb/task_group.h>
VCMI_LIB_NAMESPACE_BEGIN
/// Helper class for running asynchronous tasks using TBB thread pool
class AsyncRunner : boost::noncopyable
{
tbb::task_arena arena;
tbb::task_group taskGroup;
public:
template <typename Functor>
/// Runs the provided functor asynchronously on a thread from the TBB worker pool.
template<typename Functor>
void run(Functor && f)
{
arena.enqueue(taskGroup.defer(std::forward<Functor>(f)));
}
/// Waits for all previously enqueued task.
/// Re-entrable - waiting for tasks does not prevent submitting new tasks
void wait()
{
taskGroup.wait();