Blender  V3.3
Classes | Enumerations | Functions
task_pool.cc File Reference
#include <cstdlib>
#include <memory>
#include <utility>
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_math.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 TaskPool * task_pool_create_ex (void *userdata, TaskPoolType type, eTaskPriority priority)
 
TaskPool * BLI_task_pool_create (void *userdata, eTaskPriority priority)
 
TaskPool * BLI_task_pool_create_background (void *userdata, eTaskPriority priority)
 
TaskPool * BLI_task_pool_create_suspended (void *userdata, eTaskPriority priority)
 
TaskPool * BLI_task_pool_create_no_threads (void *userdata)
 
TaskPool * BLI_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)
 
ThreadMutex * BLI_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 133 of file task_pool.cc.

Function Documentation

◆ background_task_pool_cancel()

static void background_task_pool_cancel ( TaskPool *  pool)
static

◆ background_task_pool_canceled()

static bool background_task_pool_canceled ( TaskPool *  pool)
static

◆ 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()

TaskPool* BLI_task_pool_create ( void *  userdata,
eTaskPriority  priority 
)

◆ BLI_task_pool_create_background()

TaskPool* BLI_task_pool_create_background ( void *  userdata,
eTaskPriority  priority 
)

Create a background task pool. In multi-threaded context, there is no differences with BLI_task_pool_create(), but in single-threaded case it is ensured to have at least one worker thread to run on (i.e. you don't have to call BLI_task_pool_work_and_wait on it to be sure it will be processed).

Note
Background pools are non-recursive (that is, you should not create other background pools in tasks assigned to a background pool, they could end never being executed, since the 'fallback' background thread is already busy with parent task in single-threaded context).

Definition at line 407 of file task_pool.cc.

References TASK_POOL_BACKGROUND, and task_pool_create_ex().

Referenced by filelist_cache_preview_ensure_running().

◆ BLI_task_pool_create_background_serial()

TaskPool* BLI_task_pool_create_background_serial ( void *  userdata,
eTaskPriority  priority 
)

Task pool that executes one task after the other, possibly on different threads but never in parallel.

Definition at line 435 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)

Single threaded task pool that executes pushed task immediately, for debugging purposes.

Definition at line 426 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 
)

Similar to BLI_task_pool_create() but does not schedule any tasks for execution for until BLI_task_pool_work_and_wait() is called. This helps reducing threading overhead when pushing huge amount of small initial tasks from the main thread.

Definition at line 417 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 510 of file task_pool.cc.

References background_task_pool_canceled(), BLI_assert_msg, blender::compositor::pool, 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.

◆ BLI_task_pool_free()

void BLI_task_pool_free ( TaskPool *  pool)

◆ BLI_task_pool_push()

void BLI_task_pool_push ( TaskPool *  pool,
TaskRunFunction  run,
void *  taskdata,
bool  free_taskdata,
TaskFreeFunction  freedata 
)

◆ 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 530 of file task_pool.cc.

References blender::compositor::pool, and TaskPool::user_mutex.

◆ BLI_task_pool_work_and_wait()

void BLI_task_pool_work_and_wait ( TaskPool *  pool)

◆ task_pool_create_ex()

static TaskPool* task_pool_create_ex ( void *  userdata,
TaskPoolType  type,
eTaskPriority  priority 
)
static

◆ tbb_task_pool_cancel()

static void tbb_task_pool_cancel ( TaskPool *  pool)
static

◆ tbb_task_pool_canceled()

static bool tbb_task_pool_canceled ( TaskPool *  pool)
static

◆ tbb_task_pool_create()

static void tbb_task_pool_create ( TaskPool *  pool,
eTaskPriority  priority 
)
static

◆ 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()

static void tbb_task_pool_work_and_wait ( TaskPool *  pool)
static