Blender V4.3
BLI_threads.h File Reference
#include <pthread.h>
#include "BLI_sys_types.h"

Go to the source code of this file.

Macros

#define BLENDER_MAX_THREADS   1024
 
#define BLI_MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER
 
#define THREAD_LOCK_READ   1
 
#define THREAD_LOCK_WRITE   2
 
#define BLI_RWLOCK_INITIALIZER   PTHREAD_RWLOCK_INITIALIZER
 
#define ThreadLocal(type)   __thread type
 
#define BLI_thread_local_create(name)
 
#define BLI_thread_local_delete(name)
 
#define BLI_thread_local_get(name)   name
 
#define BLI_thread_local_set(name, value)   name = value
 

Typedefs

typedef pthread_mutex_t ThreadMutex
 
typedef pthread_spinlock_t SpinLock
 
typedef pthread_rwlock_t ThreadRWMutex
 
typedef struct TicketMutex TicketMutex
 
typedef pthread_cond_t ThreadCondition
 
typedef struct ThreadQueue ThreadQueue
 

Enumerations

enum  {
  LOCK_IMAGE = 0 , LOCK_DRAW_IMAGE , LOCK_VIEWER , LOCK_CUSTOM1 ,
  LOCK_NODES , LOCK_MOVIECLIP , LOCK_COLORMANAGE , LOCK_FFTW ,
  LOCK_VIEW3D
}
 

Functions

void BLI_threadapi_init (void)
 
void BLI_threadapi_exit (void)
 
void BLI_threadpool_init (struct ListBase *threadbase, void *(*do_thread)(void *), int tot)
 
int BLI_available_threads (struct ListBase *threadbase)
 
int BLI_threadpool_available_thread_index (struct ListBase *threadbase)
 
void BLI_threadpool_insert (struct ListBase *threadbase, void *callerdata)
 
void BLI_threadpool_remove (struct ListBase *threadbase, void *callerdata)
 
void BLI_threadpool_remove_index (struct ListBase *threadbase, int index)
 
void BLI_threadpool_clear (struct ListBase *threadbase)
 
void BLI_threadpool_end (struct ListBase *threadbase)
 
int BLI_thread_is_main (void)
 
int BLI_system_thread_count (void)
 
void BLI_system_num_threads_override_set (int num)
 
int BLI_system_num_threads_override_get (void)
 
void BLI_thread_lock (int type)
 
void BLI_thread_unlock (int type)
 
void BLI_mutex_init (ThreadMutex *mutex)
 
void BLI_mutex_end (ThreadMutex *mutex)
 
ThreadMutexBLI_mutex_alloc (void)
 
void BLI_mutex_free (ThreadMutex *mutex)
 
void BLI_mutex_lock (ThreadMutex *mutex)
 
bool BLI_mutex_trylock (ThreadMutex *mutex)
 
void BLI_mutex_unlock (ThreadMutex *mutex)
 
void BLI_spin_init (SpinLock *spin)
 
void BLI_spin_lock (SpinLock *spin)
 
void BLI_spin_unlock (SpinLock *spin)
 
void BLI_spin_end (SpinLock *spin)
 
void BLI_rw_mutex_init (ThreadRWMutex *mutex)
 
void BLI_rw_mutex_end (ThreadRWMutex *mutex)
 
ThreadRWMutexBLI_rw_mutex_alloc (void)
 
void BLI_rw_mutex_free (ThreadRWMutex *mutex)
 
void BLI_rw_mutex_lock (ThreadRWMutex *mutex, int mode)
 
void BLI_rw_mutex_unlock (ThreadRWMutex *mutex)
 
TicketMutexBLI_ticket_mutex_alloc (void)
 
void BLI_ticket_mutex_free (TicketMutex *ticket)
 
void BLI_ticket_mutex_lock (TicketMutex *ticket)
 
bool BLI_ticket_mutex_lock_check_recursive (TicketMutex *ticket)
 
void BLI_ticket_mutex_unlock (TicketMutex *ticket)
 
void BLI_condition_init (ThreadCondition *cond)
 
void BLI_condition_wait (ThreadCondition *cond, ThreadMutex *mutex)
 
void BLI_condition_wait_global_mutex (ThreadCondition *cond, int type)
 
void BLI_condition_notify_one (ThreadCondition *cond)
 
void BLI_condition_notify_all (ThreadCondition *cond)
 
void BLI_condition_end (ThreadCondition *cond)
 
ThreadQueueBLI_thread_queue_init (void)
 
void BLI_thread_queue_free (ThreadQueue *queue)
 
void BLI_thread_queue_push (ThreadQueue *queue, void *work)
 
void * BLI_thread_queue_pop (ThreadQueue *queue)
 
void * BLI_thread_queue_pop_timeout (ThreadQueue *queue, int ms)
 
int BLI_thread_queue_len (ThreadQueue *queue)
 
bool BLI_thread_queue_is_empty (ThreadQueue *queue)
 
void BLI_thread_queue_wait_finish (ThreadQueue *queue)
 
void BLI_thread_queue_nowait (ThreadQueue *queue)
 

Macro Definition Documentation

◆ BLENDER_MAX_THREADS

◆ BLI_MUTEX_INITIALIZER

#define BLI_MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER

◆ BLI_RWLOCK_INITIALIZER

#define BLI_RWLOCK_INITIALIZER   PTHREAD_RWLOCK_INITIALIZER

Definition at line 124 of file BLI_threads.h.

◆ BLI_thread_local_create

#define BLI_thread_local_create ( name)

◆ BLI_thread_local_delete

◆ BLI_thread_local_get

#define BLI_thread_local_get ( name)    name

◆ BLI_thread_local_set

#define BLI_thread_local_set ( name,
value )   name = value

◆ THREAD_LOCK_READ

◆ THREAD_LOCK_WRITE

◆ ThreadLocal

#define ThreadLocal ( type)    __thread type

Definition at line 191 of file BLI_threads.h.

Typedef Documentation

◆ SpinLock

typedef pthread_spinlock_t SpinLock

Definition at line 111 of file BLI_threads.h.

◆ ThreadCondition

typedef pthread_cond_t ThreadCondition

Definition at line 152 of file BLI_threads.h.

◆ ThreadMutex

typedef pthread_mutex_t ThreadMutex

Definition at line 83 of file BLI_threads.h.

◆ ThreadQueue

typedef struct ThreadQueue ThreadQueue

Definition at line 165 of file BLI_threads.h.

◆ ThreadRWMutex

typedef pthread_rwlock_t ThreadRWMutex

Definition at line 126 of file BLI_threads.h.

◆ TicketMutex

typedef struct TicketMutex TicketMutex

Definition at line 142 of file BLI_threads.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Global Mutex Locks

One custom lock available now. can be extended.

Enumerator
LOCK_IMAGE 
LOCK_DRAW_IMAGE 
LOCK_VIEWER 
LOCK_CUSTOM1 
LOCK_NODES 
LOCK_MOVIECLIP 
LOCK_COLORMANAGE 
LOCK_FFTW 
LOCK_VIEW3D 

Definition at line 66 of file BLI_threads.h.

Function Documentation

◆ BLI_available_threads()

int BLI_available_threads ( struct ListBase * threadbase)

Amount of available threads.

Definition at line 146 of file threads.cc.

References LISTBASE_FOREACH.

Referenced by background_task_pool_run(), and ZstdWriteWrap::write().

◆ BLI_condition_end()

◆ BLI_condition_init()

◆ BLI_condition_notify_all()

void BLI_condition_notify_all ( ThreadCondition * cond)

Definition at line 597 of file threads.cc.

Referenced by IMB_thumb_path_unlock(), and write_result().

◆ BLI_condition_notify_one()

◆ BLI_condition_wait()

◆ BLI_condition_wait_global_mutex()

void BLI_condition_wait_global_mutex ( ThreadCondition * cond,
int type )

Definition at line 587 of file threads.cc.

References global_mutex_from_type().

Referenced by IMB_thumb_path_lock().

◆ BLI_mutex_alloc()

ThreadMutex * BLI_mutex_alloc ( void )

Definition at line 365 of file threads.cc.

References BLI_mutex_init(), MEM_callocN, and mutex.

Referenced by sequencer_preview_add_sound().

◆ BLI_mutex_end()

◆ BLI_mutex_free()

void BLI_mutex_free ( ThreadMutex * mutex)

Definition at line 372 of file threads.cc.

References BLI_mutex_end(), MEM_freeN(), and mutex.

Referenced by free_preview_job().

◆ BLI_mutex_init()

◆ BLI_mutex_lock()

void BLI_mutex_lock ( ThreadMutex * mutex)

Definition at line 345 of file threads.cc.

References mutex.

Referenced by BKE_collection_object_cache_get(), BKE_collection_object_cache_instanced_get(), BKE_image_acquire_ibuf(), BKE_image_acquire_multilayer_view_ibuf(), BKE_image_acquire_renderresult(), BKE_image_ensure_viewer_views(), BKE_image_file_format_set(), BKE_image_free_anim_ibufs(), BKE_image_free_buffers_ex(), BKE_image_get_first_ibuf(), BKE_image_get_ibuf_with_name(), BKE_image_has_ibuf(), BKE_image_has_loaded_ibuf(), BKE_image_is_dirty_writable(), BKE_image_merge(), BKE_image_multilayer_stamp_info_callback(), BKE_image_pool_acquire_ibuf(), BKE_image_pool_free(), BKE_image_release_ibuf(), BKE_image_release_renderresult(), BKE_image_signal(), blf_cache_face_requester(), blf_ensure_face(), blf_font_free(), BLI_spin_lock(), bvhcache_find(), ccgDM_copyFinalCornerEdgeArray(), colorspace_from_scene_linear_cpu_processor(), colorspace_to_scene_linear_cpu_processor(), COM_deinitialize(), COM_execute(), display_from_scene_linear_processor(), display_to_scene_linear_processor(), draw_image_cache(), blender::draw::DRW_cache_free_old_subdiv(), blender::draw::DRW_subdiv_cache_free(), engine_render_view_layer(), evaluate_driver_python(), blender::compositor::ExecutionSystem::execute_work(), filelist_readjob_append_entries(), filelist_readjob_startjob(), filelist_readjob_update(), free_read_sound_waveform_task(), give_parvert(), gpu_batch_presets_register(), gpu_batch_presets_unregister(), gpu_free_unused_buffers(), GPU_pass_async_compilation_try_finalize(), GPU_pass_begin_async_compilation(), GPU_pass_compile(), image_free_gpu(), image_mem_size(), IMB_colormanagement_color_picking_to_scene_linear_v3(), IMB_colormanagement_scene_linear_to_color_picking_v3(), blender::seq::media_presence_free(), blender::seq::media_presence_invalidate_sound(), blender::seq::media_presence_invalidate_strip(), blender::seq::media_presence_is_missing(), blender::seq::media_presence_set_missing(), mempool_asan_lock(), preview_startjob(), RE_engine_draw_acquire(), RE_engine_gpu_context_enable(), RE_engine_gpu_context_lock(), RE_engine_update_render_passes(), RE_point_density_cache(), RE_point_density_sample(), RNA_property_pointer_get(), schedule_write_result(), screen_opengl_render_end(), seq_cache_create(), seq_cache_lock(), seq_disk_cache_enforce_limits(), seq_disk_cache_invalidate(), seq_disk_cache_read_file(), seq_disk_cache_write_file(), seq_prefetch_do_suspend(), SEQ_render_give_ibuf(), sequencer_preview_add_sound(), stats_background(), view_layer_bases_hash_create(), ZstdWriteWrap::write(), and write_result().

◆ BLI_mutex_trylock()

bool BLI_mutex_trylock ( ThreadMutex * mutex)

Definition at line 355 of file threads.cc.

References mutex.

◆ BLI_mutex_unlock()

void BLI_mutex_unlock ( ThreadMutex * mutex)

Definition at line 350 of file threads.cc.

References mutex.

Referenced by BKE_collection_object_cache_get(), BKE_collection_object_cache_instanced_get(), BKE_image_acquire_ibuf(), BKE_image_acquire_multilayer_view_ibuf(), BKE_image_acquire_renderresult(), BKE_image_ensure_viewer_views(), BKE_image_file_format_set(), BKE_image_free_anim_ibufs(), BKE_image_free_buffers_ex(), BKE_image_get_first_ibuf(), BKE_image_get_ibuf_with_name(), BKE_image_has_ibuf(), BKE_image_has_loaded_ibuf(), BKE_image_is_dirty_writable(), BKE_image_merge(), BKE_image_multilayer_stamp_info_callback(), BKE_image_pool_acquire_ibuf(), BKE_image_pool_free(), BKE_image_release_ibuf(), BKE_image_release_renderresult(), BKE_image_signal(), blf_cache_face_requester(), blf_ensure_face(), blf_font_free(), BLI_spin_unlock(), bvhcache_find(), bvhcache_unlock(), ccgDM_copyFinalCornerEdgeArray(), colorspace_from_scene_linear_cpu_processor(), colorspace_to_scene_linear_cpu_processor(), COM_deinitialize(), COM_execute(), display_from_scene_linear_processor(), display_to_scene_linear_processor(), draw_image_cache(), blender::draw::DRW_cache_free_old_subdiv(), blender::draw::DRW_subdiv_cache_free(), engine_render_view_layer(), evaluate_driver_python(), blender::compositor::ExecutionSystem::execute_work(), filelist_readjob_append_entries(), filelist_readjob_startjob(), filelist_readjob_update(), free_read_sound_waveform_task(), give_parvert(), gpu_batch_presets_register(), gpu_batch_presets_unregister(), gpu_free_unused_buffers(), GPU_pass_async_compilation_try_finalize(), GPU_pass_begin_async_compilation(), GPU_pass_compile(), image_free_gpu(), image_mem_size(), IMB_colormanagement_color_picking_to_scene_linear_v3(), IMB_colormanagement_scene_linear_to_color_picking_v3(), blender::seq::media_presence_free(), blender::seq::media_presence_invalidate_sound(), blender::seq::media_presence_invalidate_strip(), blender::seq::media_presence_is_missing(), blender::seq::media_presence_set_missing(), mempool_asan_unlock(), preview_startjob(), RE_engine_draw_acquire(), RE_engine_draw_release(), RE_engine_gpu_context_disable(), RE_engine_gpu_context_unlock(), RE_engine_update_render_passes(), RE_point_density_cache(), RE_point_density_sample(), RNA_property_pointer_get(), schedule_write_result(), screen_opengl_render_end(), seq_cache_create(), seq_cache_unlock(), seq_disk_cache_create(), seq_disk_cache_enforce_limits(), seq_disk_cache_invalidate(), seq_disk_cache_read_file(), seq_disk_cache_write_file(), seq_prefetch_do_suspend(), SEQ_render_give_ibuf(), sequencer_preview_add_sound(), stats_background(), view_layer_bases_hash_create(), ZstdWriteWrap::write(), and write_result().

◆ BLI_rw_mutex_alloc()

ThreadRWMutex * BLI_rw_mutex_alloc ( void )

◆ BLI_rw_mutex_end()

void BLI_rw_mutex_end ( ThreadRWMutex * mutex)

Definition at line 482 of file threads.cc.

References mutex.

Referenced by BLI_rw_mutex_free(), ccgDM_release(), and BaseRender::~BaseRender().

◆ BLI_rw_mutex_free()

void BLI_rw_mutex_free ( ThreadRWMutex * mutex)

Definition at line 495 of file threads.cc.

References BLI_rw_mutex_end(), MEM_freeN(), and mutex.

Referenced by fluid_modifier_freeDomain().

◆ BLI_rw_mutex_init()

void BLI_rw_mutex_init ( ThreadRWMutex * mutex)

Definition at line 462 of file threads.cc.

References mutex.

Referenced by BLI_rw_mutex_alloc(), and getCCGDerivedMesh().

◆ BLI_rw_mutex_lock()

◆ BLI_rw_mutex_unlock()

◆ BLI_spin_end()

◆ BLI_spin_init()

◆ BLI_spin_lock()

◆ BLI_spin_unlock()

◆ BLI_system_num_threads_override_get()

int BLI_system_num_threads_override_get ( void )

Definition at line 294 of file threads.cc.

References threads_override_num.

Referenced by BKE_render_num_threads(), BLI_task_scheduler_init(), and OIIO_init().

◆ BLI_system_num_threads_override_set()

void BLI_system_num_threads_override_set ( int num)

Definition at line 289 of file threads.cc.

References threads_override_num.

Referenced by arg_handle_threads_set().

◆ BLI_system_thread_count()

◆ BLI_thread_is_main()

int BLI_thread_is_main ( void )

Definition at line 179 of file threads.cc.

References mainid.

Referenced by BKE_icon_geom_ensure(), BKE_icon_geom_from_file(), BKE_icon_geom_from_memory(), BKE_icon_get(), BKE_icon_gplayer_color_ensure(), BKE_icon_id_delete(), BKE_icon_id_ensure(), BKE_icons_free(), BKE_icons_init(), BKE_image_free_gputextures(), BKE_image_free_unused_gpu_textures(), BKE_previewimg_cached_ensure(), BKE_previewimg_cached_get(), BKE_previewimg_cached_release(), BKE_previewimg_cached_thumbnail_read(), BLI_change_working_dir(), BLT_translate(), BPY_context_update(), ctx_data_get(), ctx_wm_python_context_get(), blender::gpu::VKDevice::debug_print(), blender::gpu::VKDevice::discard_pool_for_current_thread(), DRW_blender_gpu_render_context_enable(), DRW_gpu_context_activate(), DRW_gpu_context_destroy(), DRW_gpu_context_disable_ex(), DRW_gpu_context_release(), DRW_system_gpu_render_context_enable(), ED_preview_ensure_dbase(), ED_render_id_flush_update(), ED_render_scene_update(), engine_depsgraph_free(), blender::render::RealtimeCompositor::execute(), GPU_batch_preset_sphere(), GPU_batch_preset_sphere_wire(), icon_gplayer_color_ensure_create_icon(), icon_id_ensure_create_icon(), image_init_after_load(), blender::eevee::LightBake::LightBake(), RE_engine_gpu_context_create(), RE_FreeUnusedGPUResources(), RE_system_gpu_context_ensure(), RE_system_gpu_context_free(), blender::gpu::VKBackend::render_end(), SEQ_effect_text_font_load(), seq_render_scene_strip(), blender::eevee::LightBake::update(), wm_file_write(), wm_job_end(), wm_surface_reset_drawable(), WM_system_gpu_context_create(), wm_window_events_process(), wm_window_reset_drawable(), blender::eevee::LightBake::~LightBake(), and blender::render::RealtimeCompositor::~RealtimeCompositor().

◆ BLI_thread_lock()

◆ BLI_thread_queue_free()

◆ BLI_thread_queue_init()

◆ BLI_thread_queue_is_empty()

bool BLI_thread_queue_is_empty ( ThreadQueue * queue)

Definition at line 759 of file threads.cc.

References BLI_gsqueue_is_empty().

Referenced by filelist_cache_previews_update().

◆ BLI_thread_queue_len()

int BLI_thread_queue_len ( ThreadQueue * queue)

Definition at line 748 of file threads.cc.

References BLI_gsqueue_len(), and size().

◆ BLI_thread_queue_nowait()

◆ BLI_thread_queue_pop()

◆ BLI_thread_queue_pop_timeout()

void * BLI_thread_queue_pop_timeout ( ThreadQueue * queue,
int ms )

◆ BLI_thread_queue_push()

◆ BLI_thread_queue_wait_finish()

void BLI_thread_queue_wait_finish ( ThreadQueue * queue)

◆ BLI_thread_unlock()

◆ BLI_threadapi_exit()

void BLI_threadapi_exit ( void )

◆ BLI_threadapi_init()

void BLI_threadapi_init ( void )

This is run once at startup.

Definition at line 114 of file threads.cc.

References mainid.

Referenced by main(), blender::tests::ChangeWorkingDirectoryTest::SetUp(), BlendfileLoadingBaseTest::SetUpTestCase(), TEST(), TEST(), and TEST().

◆ BLI_threadpool_available_thread_index()

int BLI_threadpool_available_thread_index ( struct ListBase * threadbase)

Returns thread number, for sample patterns or threadsafe tables.

Definition at line 159 of file threads.cc.

References LISTBASE_FOREACH.

◆ BLI_threadpool_clear()

void BLI_threadpool_clear ( struct ListBase * threadbase)

Definition at line 223 of file threads.cc.

References LISTBASE_FOREACH.

Referenced by background_task_pool_work_and_wait().

◆ BLI_threadpool_end()

◆ BLI_threadpool_init()

void BLI_threadpool_init ( struct ListBase * threadbase,
void *(* do_thread )(void *),
int tot )

◆ BLI_threadpool_insert()

◆ BLI_threadpool_remove()

void BLI_threadpool_remove ( struct ListBase * threadbase,
void * callerdata )

◆ BLI_threadpool_remove_index()

void BLI_threadpool_remove_index ( struct ListBase * threadbase,
int index )

Definition at line 208 of file threads.cc.

References LISTBASE_FOREACH.

◆ BLI_ticket_mutex_alloc()

TicketMutex * BLI_ticket_mutex_alloc ( void )

Definition at line 511 of file threads.cc.

References TicketMutex::cond, MEM_callocN, and TicketMutex::mutex.

Referenced by DRW_gpu_context_create(), and WM_jobs_get().

◆ BLI_ticket_mutex_free()

void BLI_ticket_mutex_free ( TicketMutex * ticket)

Definition at line 522 of file threads.cc.

References TicketMutex::cond, MEM_freeN(), and TicketMutex::mutex.

Referenced by DRW_gpu_context_destroy(), and wm_job_free().

◆ BLI_ticket_mutex_lock()

◆ BLI_ticket_mutex_lock_check_recursive()

bool BLI_ticket_mutex_lock_check_recursive ( TicketMutex * ticket)

Definition at line 559 of file threads.cc.

References ticket_mutex_lock().

Referenced by DRW_notify_view_update().

◆ BLI_ticket_mutex_unlock()