diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-10 15:59:19 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-10 15:59:19 +0300 |
commit | a1d8fe052ccd8945f14be5a50bd5af581b89c643 (patch) | |
tree | 659751be8507afb09359bde8675de9762388bb2f /source/blender/blenlib | |
parent | 923925780650de4736d580f984a6b6001b786a15 (diff) |
Task scheduler: Avoid mutex lock in number manipulation functions
It seems using atomic operations here we can avoid having mute without
breaking anything.
Thanks Bastien for double-checking the changes!
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/task.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index b47931cdde9..a62ba734a3c 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -230,28 +230,21 @@ static void task_free(TaskPool *pool, Task *task, const int thread_id) static void task_pool_num_decrease(TaskPool *pool, size_t done) { - BLI_mutex_lock(&pool->num_mutex); - BLI_assert(pool->num >= done); - pool->num -= done; + atomic_sub_z((size_t*)&pool->num, done); atomic_sub_z(&pool->currently_running_tasks, done); - pool->done += done; + atomic_add_z((size_t*)&pool->done, done); - if (pool->num == 0) + if (pool->num == 0) { BLI_condition_notify_all(&pool->num_cond); - - BLI_mutex_unlock(&pool->num_mutex); + } } static void task_pool_num_increase(TaskPool *pool) { - BLI_mutex_lock(&pool->num_mutex); - - pool->num++; + atomic_add_z((size_t*)&pool->num, 1); BLI_condition_notify_all(&pool->num_cond); - - BLI_mutex_unlock(&pool->num_mutex); } static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task) |