Blender V4.3
task_pool.cc File Reference
#include <cstdlib>
#include <memory>
#include <utility>
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_mempool.h"
#include "BLI_task.h"
#include "BLI_threads.h"

Go to the source code of this file.

Classes

class  Task
 
class  TaskPool
 

Enumerations

enum  TaskPoolType {
  TASK_POOL_TBB , TASK_POOL_TBB_SUSPENDED , TASK_POOL_NO_THREADS , TASK_POOL_BACKGROUND ,
  TASK_POOL_BACKGROUND_SERIAL
}
 

Functions

static void tbb_task_pool_create (TaskPool *pool, eTaskPriority priority)
 
static void tbb_task_pool_run (TaskPool *pool, Task &&task)
 
static void tbb_task_pool_work_and_wait (TaskPool *pool)
 
static void tbb_task_pool_cancel (TaskPool *pool)
 
static bool tbb_task_pool_canceled (TaskPool *pool)
 
static void tbb_task_pool_free (TaskPool *pool)
 
static void * background_task_run (void *userdata)
 
static void background_task_pool_create (TaskPool *pool)
 
static void background_task_pool_run (TaskPool *pool, Task &&task)
 
static void background_task_pool_work_and_wait (TaskPool *pool)
 
static void background_task_pool_cancel (TaskPool *pool)
 
static bool background_task_pool_canceled (TaskPool *pool)
 
static void background_task_pool_free (TaskPool *pool)
 
static TaskPooltask_pool_create_ex (void *userdata, TaskPoolType type, eTaskPriority priority)
 
TaskPoolBLI_task_pool_create (void *userdata, eTaskPriority priority)
 
TaskPoolBLI_task_pool_create_background (void *userdata, eTaskPriority priority)
 
TaskPoolBLI_task_pool_create_suspended (void *userdata, eTaskPriority priority)
 
TaskPoolBLI_task_pool_create_no_threads (void *userdata)
 
TaskPoolBLI_task_pool_create_background_serial (void *userdata, eTaskPriority priority)
 
void BLI_task_pool_free (TaskPool *pool)
 
void BLI_task_pool_push (TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
 
void BLI_task_pool_work_and_wait (TaskPool *pool)
 
void BLI_task_pool_cancel (TaskPool *pool)
 
bool BLI_task_pool_current_canceled (TaskPool *pool)
 
void * BLI_task_pool_user_data (TaskPool *pool)
 
ThreadMutexBLI_task_pool_user_mutex (TaskPool *pool)
 

Detailed Description

Task pool to run tasks in parallel.

Definition in file task_pool.cc.

Enumeration Type Documentation

◆ TaskPoolType

Enumerator
TASK_POOL_TBB 
TASK_POOL_TBB_SUSPENDED 
TASK_POOL_NO_THREADS 
TASK_POOL_BACKGROUND 
TASK_POOL_BACKGROUND_SERIAL 

Definition at line 140 of file task_pool.cc.

Function Documentation

◆ background_task_pool_cancel()

◆ background_task_pool_canceled()

static bool background_task_pool_canceled ( TaskPool * pool)
static

Definition at line 344 of file task_pool.cc.

References TaskPool::background_is_canceling.

Referenced by BLI_task_pool_current_canceled().

◆ background_task_pool_create()

static void background_task_pool_create ( TaskPool * pool)
static

◆ background_task_pool_free()

static void background_task_pool_free ( TaskPool * pool)
static

◆ background_task_pool_run()

static void background_task_pool_run ( TaskPool * pool,
Task && task )
static

◆ background_task_pool_work_and_wait()

static void background_task_pool_work_and_wait ( TaskPool * pool)
static

◆ background_task_run()

static void * background_task_run ( void * userdata)
static

◆ BLI_task_pool_cancel()

void BLI_task_pool_cancel ( TaskPool * pool)

◆ BLI_task_pool_create()

◆ BLI_task_pool_create_background()

TaskPool * BLI_task_pool_create_background ( void * userdata,
eTaskPriority priority )

Background: always run tasks in a background thread, never immediately execute them. For running background jobs.

Definition at line 399 of file task_pool.cc.

References TASK_POOL_BACKGROUND, and task_pool_create_ex().

Referenced by filelist_cache_preview_ensure_running(), and undomesh_from_editmesh().

◆ BLI_task_pool_create_background_serial()

TaskPool * BLI_task_pool_create_background_serial ( void * userdata,
eTaskPriority priority )

Background Serial: run tasks one after the other in the background.

Executes one task after the other, possibly on different threads but never in parallel.

Definition at line 426 of file task_pool.cc.

References TASK_POOL_BACKGROUND_SERIAL, and task_pool_create_ex().

Referenced by screen_opengl_render_init().

◆ BLI_task_pool_create_no_threads()

TaskPool * BLI_task_pool_create_no_threads ( void * userdata)

No threads: immediately executes tasks on the same thread. For debugging purposes.

Definition at line 421 of file task_pool.cc.

References task_pool_create_ex(), TASK_POOL_NO_THREADS, and TASK_PRIORITY_HIGH.

◆ BLI_task_pool_create_suspended()

TaskPool * BLI_task_pool_create_suspended ( void * userdata,
eTaskPriority priority )

Suspended: don't execute tasks until work_and_wait is called. This is slower as threads can't immediately start working. But it can be used if the data structures the threads operate on are not fully initialized until all tasks are created.

Definition at line 413 of file task_pool.cc.

References task_pool_create_ex(), and TASK_POOL_TBB_SUSPENDED.

Referenced by project_paint_op(), and TEST().

◆ BLI_task_pool_current_canceled()

bool BLI_task_pool_current_canceled ( TaskPool * pool)

For worker threads, test if current task pool canceled. this function may only be called from worker threads and pool must be the task pool that the thread is currently executing a task from.

Definition at line 501 of file task_pool.cc.

References background_task_pool_canceled(), BLI_assert_msg, TASK_POOL_BACKGROUND, TASK_POOL_BACKGROUND_SERIAL, TASK_POOL_NO_THREADS, TASK_POOL_TBB, TASK_POOL_TBB_SUSPENDED, tbb_task_pool_canceled(), and TaskPool::type.

Referenced by execute_read_sound_waveform_task().

◆ BLI_task_pool_free()

◆ BLI_task_pool_push()

◆ BLI_task_pool_user_data()

void * BLI_task_pool_user_data ( TaskPool * pool)

◆ BLI_task_pool_user_mutex()

ThreadMutex * BLI_task_pool_user_mutex ( TaskPool * pool)

Optional mutex to use from run function.

Definition at line 521 of file task_pool.cc.

References TaskPool::user_mutex.

◆ BLI_task_pool_work_and_wait()

◆ task_pool_create_ex()

◆ tbb_task_pool_cancel()

static void tbb_task_pool_cancel ( TaskPool * pool)
static

Definition at line 249 of file task_pool.cc.

References TaskPool::tbb_group, UNUSED_VARS, and TaskPool::use_threads.

Referenced by BLI_task_pool_cancel().

◆ tbb_task_pool_canceled()

static bool tbb_task_pool_canceled ( TaskPool * pool)
static

Definition at line 261 of file task_pool.cc.

References UNUSED_VARS, and TaskPool::use_threads.

Referenced by BLI_task_pool_current_canceled().

◆ tbb_task_pool_create()

◆ tbb_task_pool_free()

static void tbb_task_pool_free ( TaskPool * pool)
static

◆ tbb_task_pool_run()

static void tbb_task_pool_run ( TaskPool * pool,
Task && task )
static

◆ tbb_task_pool_work_and_wait()