Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/threads.c
| Show First 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | |||||
| int BLI_system_num_threads_override_get(void) | int BLI_system_num_threads_override_get(void) | ||||
| { | { | ||||
| return num_threads_override; | return num_threads_override; | ||||
| } | } | ||||
| /* Global Mutex Locks */ | /* Global Mutex Locks */ | ||||
| static ThreadMutex *global_mutex_from_type(const int type) | |||||
| { | |||||
| switch (type) { | |||||
| case LOCK_IMAGE: | |||||
| return &_image_lock; | |||||
| case LOCK_DRAW_IMAGE: | |||||
| return &_image_draw_lock; | |||||
| case LOCK_VIEWER: | |||||
| return &_viewer_lock; | |||||
| case LOCK_CUSTOM1: | |||||
| return &_custom1_lock; | |||||
| case LOCK_RCACHE: | |||||
| return &_rcache_lock; | |||||
| case LOCK_OPENGL: | |||||
| return &_opengl_lock; | |||||
| case LOCK_NODES: | |||||
| return &_nodes_lock; | |||||
| case LOCK_MOVIECLIP: | |||||
| return &_movieclip_lock; | |||||
| case LOCK_COLORMANAGE: | |||||
| return &_colormanage_lock; | |||||
| case LOCK_FFTW: | |||||
| return &_fftw_lock; | |||||
| case LOCK_VIEW3D: | |||||
| return &_view3d_lock; | |||||
| default: | |||||
| BLI_assert(0); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| void BLI_lock_thread(int type) | void BLI_lock_thread(int type) | ||||
| { | { | ||||
| if (type == LOCK_IMAGE) | pthread_mutex_lock(global_mutex_from_type(type)); | ||||
| pthread_mutex_lock(&_image_lock); | |||||
| else if (type == LOCK_DRAW_IMAGE) | |||||
| pthread_mutex_lock(&_image_draw_lock); | |||||
| else if (type == LOCK_VIEWER) | |||||
| pthread_mutex_lock(&_viewer_lock); | |||||
| else if (type == LOCK_CUSTOM1) | |||||
| pthread_mutex_lock(&_custom1_lock); | |||||
| else if (type == LOCK_RCACHE) | |||||
| pthread_mutex_lock(&_rcache_lock); | |||||
| else if (type == LOCK_OPENGL) | |||||
| pthread_mutex_lock(&_opengl_lock); | |||||
| else if (type == LOCK_NODES) | |||||
| pthread_mutex_lock(&_nodes_lock); | |||||
| else if (type == LOCK_MOVIECLIP) | |||||
| pthread_mutex_lock(&_movieclip_lock); | |||||
| else if (type == LOCK_COLORMANAGE) | |||||
| pthread_mutex_lock(&_colormanage_lock); | |||||
| else if (type == LOCK_FFTW) | |||||
| pthread_mutex_lock(&_fftw_lock); | |||||
| else if (type == LOCK_VIEW3D) | |||||
| pthread_mutex_lock(&_view3d_lock); | |||||
| } | } | ||||
| void BLI_unlock_thread(int type) | void BLI_unlock_thread(int type) | ||||
| { | { | ||||
| if (type == LOCK_IMAGE) | pthread_mutex_unlock(global_mutex_from_type(type)); | ||||
| pthread_mutex_unlock(&_image_lock); | |||||
| else if (type == LOCK_DRAW_IMAGE) | |||||
| pthread_mutex_unlock(&_image_draw_lock); | |||||
| else if (type == LOCK_VIEWER) | |||||
| pthread_mutex_unlock(&_viewer_lock); | |||||
| else if (type == LOCK_CUSTOM1) | |||||
| pthread_mutex_unlock(&_custom1_lock); | |||||
| else if (type == LOCK_RCACHE) | |||||
| pthread_mutex_unlock(&_rcache_lock); | |||||
| else if (type == LOCK_OPENGL) | |||||
| pthread_mutex_unlock(&_opengl_lock); | |||||
| else if (type == LOCK_NODES) | |||||
| pthread_mutex_unlock(&_nodes_lock); | |||||
| else if (type == LOCK_MOVIECLIP) | |||||
| pthread_mutex_unlock(&_movieclip_lock); | |||||
| else if (type == LOCK_COLORMANAGE) | |||||
| pthread_mutex_unlock(&_colormanage_lock); | |||||
| else if (type == LOCK_FFTW) | |||||
| pthread_mutex_unlock(&_fftw_lock); | |||||
| else if (type == LOCK_VIEW3D) | |||||
| pthread_mutex_unlock(&_view3d_lock); | |||||
| } | } | ||||
| /* Mutex Locks */ | /* Mutex Locks */ | ||||
| void BLI_mutex_init(ThreadMutex *mutex) | void BLI_mutex_init(ThreadMutex *mutex) | ||||
| { | { | ||||
| pthread_mutex_init(mutex, NULL); | pthread_mutex_init(mutex, NULL); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | void BLI_condition_init(ThreadCondition *cond) | ||||
| pthread_cond_init(cond, NULL); | pthread_cond_init(cond, NULL); | ||||
| } | } | ||||
| void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *mutex) | void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *mutex) | ||||
| { | { | ||||
| pthread_cond_wait(cond, mutex); | pthread_cond_wait(cond, mutex); | ||||
| } | } | ||||
| void BLI_condition_wait_global_mutex(ThreadCondition *cond, const int type) | |||||
| { | |||||
| pthread_cond_wait(cond, global_mutex_from_type(type)); | |||||
| } | |||||
| void BLI_condition_notify_one(ThreadCondition *cond) | void BLI_condition_notify_one(ThreadCondition *cond) | ||||
| { | { | ||||
| pthread_cond_signal(cond); | pthread_cond_signal(cond); | ||||
| } | } | ||||
| void BLI_condition_notify_all(ThreadCondition *cond) | void BLI_condition_notify_all(ThreadCondition *cond) | ||||
| { | { | ||||
| pthread_cond_broadcast(cond); | pthread_cond_broadcast(cond); | ||||
| ▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines | |||||