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:
authorSergey Sharybin <sergey.vfx@gmail.com>2014-12-02 13:23:58 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2014-12-02 13:23:58 +0300
commite177c5143055306d4b128663d537568bd1256645 (patch)
tree9f78cc93f7f7d164438ee5e1220fc661dab9f121 /source/blender/blenlib/intern/task.c
parenta42638d265bbcd052dc61acc9fb403fc3d38c505 (diff)
Use atomic operations in task pool
This ensures proper values of currently running tasks in the pool (previously difference between mutex locks when acquiring new job and releasing it might in theory give wrong values).
Diffstat (limited to 'source/blender/blenlib/intern/task.c')
-rw-r--r--source/blender/blenlib/intern/task.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index e4cded18b76..d187a8d1968 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -33,6 +33,8 @@
#include "BLI_task.h"
#include "BLI_threads.h"
+#include "atomic_ops.h"
+
/* Types */
typedef struct Task {
@@ -49,8 +51,8 @@ struct TaskPool {
volatile size_t num;
volatile size_t done;
- volatile int num_threads;
- volatile int currently_running_tasks;
+ size_t num_threads;
+ size_t currently_running_tasks;
ThreadMutex num_mutex;
ThreadCondition num_cond;
@@ -86,7 +88,7 @@ static void task_pool_num_decrease(TaskPool *pool, size_t done)
BLI_assert(pool->num >= done);
pool->num -= done;
- pool->currently_running_tasks -= done;
+ atomic_sub_z(&pool->currently_running_tasks, done);
pool->done += done;
if (pool->num == 0)
@@ -130,7 +132,7 @@ static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task
{
*task = current_task;
found_task = true;
- pool->currently_running_tasks++;
+ atomic_add_z(&pool->currently_running_tasks, 1);
BLI_remlink(&scheduler->queue, *task);
break;
}
@@ -392,7 +394,7 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
/* if found task, do it, otherwise wait until other tasks are done */
if (found_task) {
/* run task */
- pool->currently_running_tasks++;
+ atomic_add_z(&pool->currently_running_tasks, 1);
work_task->run(pool, work_task->taskdata, 0);
/* delete task */