Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-08-10 16:03:31 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-10 16:03:31 +0300
commitd70ffd375fdf444f50a693f74ca79fe248337cda (patch)
tree5c5811e853aebaaa4f70d08499bd39baaf25a0b6 /source/blender/blenlib
parentc6d13716c11d428f33cf241969aaff9c14b21606 (diff)
BLI_threads: add an helper to wait on a condition using a global mutex.
Also, factorized internal code to get global mutex from its ID.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_threads.h1
-rw-r--r--source/blender/blenlib/intern/threads.c82
2 files changed, 39 insertions, 44 deletions
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index b2ead15af22..6ae833d5ed7 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -158,6 +158,7 @@ typedef pthread_cond_t ThreadCondition;
void BLI_condition_init(ThreadCondition *cond);
void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *mutex);
+void BLI_condition_wait_global_mutex(ThreadCondition *cond, const int type);
void BLI_condition_notify_one(ThreadCondition *cond);
void BLI_condition_notify_all(ThreadCondition *cond);
void BLI_condition_end(ThreadCondition *cond);
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 42f7a744b94..b60981802aa 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -389,56 +389,45 @@ int BLI_system_num_threads_override_get(void)
/* 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)
{
- if (type == LOCK_IMAGE)
- 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);
+ pthread_mutex_lock(global_mutex_from_type(type));
}
void BLI_unlock_thread(int type)
{
- if (type == LOCK_IMAGE)
- 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);
+ pthread_mutex_unlock(global_mutex_from_type(type));
}
/* Mutex Locks */
@@ -619,6 +608,11 @@ void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *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)
{
pthread_cond_signal(cond);