27# include <tbb/blocked_range.h>
28# include <tbb/task_arena.h>
29# include <tbb/task_group.h>
83 other.taskdata =
nullptr;
84 other.free_taskdata =
false;
85 other.freedata =
nullptr;
92#if (defined(WITH_TBB) && TBB_INTERFACE_VERSION_MAJOR < 10) || \
93 (defined(_MSC_VER) && defined(__clang__) && TBB_INTERFACE_VERSION_MAJOR < 12)
101 ((
Task &)other).pool =
nullptr;
102 ((
Task &)other).run =
nullptr;
103 ((
Task &)other).taskdata =
nullptr;
104 ((
Task &)other).free_taskdata =
false;
105 ((
Task &)other).freedata =
nullptr;
128class TBBTaskGroup :
public tbb::task_group {
132# if TBB_INTERFACE_VERSION_MAJOR >= 12
140 my_context.set_priority(tbb::priority_low);
143 my_context.set_priority(tbb::priority_normal);
169 std::unique_ptr<TBBTaskGroup> tbb_group;
192 switch (this->type) {
197 this->is_suspended =
true;
202 this->tbb_group = std::make_unique<TBBTaskGroup>(
priority);
225 this->background_task_pool_work_and_wait();
238 other.pool =
nullptr;
240 other.taskdata =
nullptr;
241 other.free_taskdata =
false;
242 other.freedata =
nullptr;
259 switch (this->type) {
263 this->tbb_task_pool_run({
this, run, taskdata, free_taskdata, freedata});
267 this->background_task_pool_run({
this, run, taskdata, free_taskdata, freedata});
277 switch (this->type) {
281 this->tbb_task_pool_work_and_wait();
285 this->background_task_pool_work_and_wait();
298 void tbb_task_pool_run(
Task &&task);
299 void tbb_task_pool_work_and_wait();
304 void background_task_pool_run(
Task &&task);
305 void background_task_pool_work_and_wait();
306 static void *background_task_run(
void *
userdata);
309void TaskPool::tbb_task_pool_run(Task &&task)
325 std::atomic_thread_fence(std::memory_order_release);
332 this->tbb_group->run(std::move(task));
341void TaskPool::tbb_task_pool_work_and_wait()
350 this->tbb_task_pool_run(std::move(task));
360 this->tbb_group->wait();
365void TaskPool::background_task_pool_run(
Task &&task)
369 Task *task_mem = MEM_new<Task>(__func__, std::move(task));
381void TaskPool::background_task_pool_work_and_wait()
392void *TaskPool::background_task_run(
void *userdata)
406 return MEM_new<TaskPool>(__func__,
TASK_POOL_TBB, priority, userdata);
452 pool->
task_push(run, taskdata, free_taskdata, freedata);
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
Task & operator=(const Task &other)=delete
Task(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Task & operator=(Task &&other)=delete
TaskFreeFunction freedata
Task(const Task &other)=delete
void BLI_thread_queue_nowait(ThreadQueue *queue)
int BLI_available_threads(ListBaseT< ThreadSlot > *threadbase)
@ BLI_THREAD_QUEUE_WORK_PRIORITY_HIGH
@ BLI_THREAD_QUEUE_WORK_PRIORITY_NORMAL
TaskPool * BLI_task_pool_create_suspended(void *userdata, eTaskPriority priority)
int BLI_task_scheduler_num_threads()
void BLI_thread_queue_wait_finish(ThreadQueue *queue)
void BLI_threadpool_insert(ListBaseT< ThreadSlot > *threadbase, void *callerdata)
void BLI_threadpool_end(ListBaseT< ThreadSlot > *threadbase)
TaskPool * BLI_task_pool_create_no_threads(void *userdata)
void MEM_delete_void(void *vmemh)
void BLI_task_pool_work_and_wait(TaskPool *pool)
void * BLI_task_pool_user_data(TaskPool *pool)
TaskPool * BLI_task_pool_create_background_serial(void *userdata, eTaskPriority priority)
@ TASK_POOL_TBB_SUSPENDED
@ TASK_POOL_BACKGROUND_SERIAL
void(*) TaskRunFunction(TaskPool *__restrict pool, void *taskdata)
void BLI_thread_queue_free(ThreadQueue *queue)
ThreadQueue * BLI_thread_queue_init()
void * BLI_thread_queue_pop(ThreadQueue *queue)
void BLI_task_pool_free(TaskPool *pool)
void(*) TaskFreeFunction(TaskPool *__restrict pool, void *taskdata)
TaskPool * BLI_task_pool_create(void *userdata, eTaskPriority priority)
uint64_t BLI_thread_queue_push(ThreadQueue *queue, void *work, ThreadQueueWorkPriority priority)
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
void BLI_threadpool_init(ListBaseT< ThreadSlot > *threadbase, void *(*do_thread)(void *), int tot)
void BLI_threadpool_clear(ListBaseT< ThreadSlot > *threadbase)
TaskPool * BLI_task_pool_create_background(void *userdata, eTaskPriority priority)
volatile bool is_suspended
TaskPool(const TaskPoolType type, const eTaskPriority priority, void *userdata)
TaskPool(TaskPool &&other)=delete
void task_push(TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
ListBaseT< ThreadSlot > background_threads
TaskPool(const TaskPool &other)=delete
Vector< Task > suspended_tasks
ThreadQueue * background_queue
TaskPool & operator=(TaskPool &&other)=delete
TaskPool & operator=(const TaskPool &other)=delete