19 _unfinishedTasks.store(1, std::memory_order::relaxed);
21 _parent->_unfinishedTasks.fetch_add(1, std::memory_order::relaxed);
34 return _unfinishedTasks.load(std::memory_order::relaxed) == 0;
45 _unfinishedTasks.fetch_sub(1, std::memory_order::relaxed);
52 std::function<void()> _func{};
54 std::atomic<uint16_t> _unfinishedTasks;
69 auto& task = _tasks_array[_task_counter++ & (
max_tasks - 1)];
71 new (&task)
task_t(std::forward<
decltype(func)>(func), parent);
76 static inline thread_local std::size_t _task_counter;
77 static inline thread_local std::array<task_t, max_tasks> _tasks_array;
Manages a pool of tasks, allocated from a circular array. Tasks are reused instead of being deallocat...
Definition task.hpp:59
static constexpr std::size_t max_tasks
Maximum number of tasks that can exist at any given time per worker.
Definition task.hpp:62
static task_t * allocate(auto &&func, task_t *parent=nullptr)
Allocates a task with the specified function and parent, placing it in a circular buffer.
Definition task.hpp:68
Represents a task that can be executed, monitored for completion, and linked to a parent task.
Definition task.hpp:10
task_t(auto &&func, task_t *parent=nullptr)
Constructs a task from a callable function and optionally links it to a parent task.
Definition task.hpp:18
task_t * parent() const noexcept
Retrieves the parent task if it exists.
Definition task.hpp:39
void execute()
Executes the task's function and marks it as completed.
Definition task.hpp:26
task_t()=default
Constructs an empty task.
bool is_completed() const noexcept
Checks if the task has been completed.
Definition task.hpp:33
Definition archetype.hpp:11