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:
Diffstat (limited to 'intern/cycles/util')
-rw-r--r--intern/cycles/util/util_task.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp
index ea0abd6f54f..2b209c135f4 100644
--- a/intern/cycles/util/util_task.cpp
+++ b/intern/cycles/util/util_task.cpp
@@ -38,6 +38,8 @@ TaskPool::~TaskPool()
void TaskPool::push(Task *task, bool front)
{
+ thread_scoped_lock num_lock(num_mutex);
+
TaskScheduler::Entry entry;
entry.task = task;
@@ -102,22 +104,17 @@ void TaskPool::wait_work()
void TaskPool::cancel()
{
+ thread_scoped_lock num_lock(num_mutex);
+
do_cancel = true;
TaskScheduler::clear(this);
-
- {
- thread_scoped_lock num_lock(num_mutex);
-
- while(num)
- num_cond.wait(num_lock);
- }
-
- do_cancel = false;
}
void TaskPool::stop()
{
+ thread_scoped_lock num_lock(num_mutex);
+
TaskScheduler::clear(this);
assert(num == 0);
@@ -130,20 +127,20 @@ bool TaskPool::cancelled()
void TaskPool::num_decrease(int done)
{
- num_mutex.lock();
num -= done;
-
assert(num >= 0);
- if(num == 0)
+
+ if(num == 0) {
+ do_cancel = false;
+
num_cond.notify_all();
-
- num_mutex.unlock();
+ }
}
void TaskPool::num_increase()
{
- thread_scoped_lock num_lock(num_mutex);
num++;
+
num_cond.notify_all();
}
@@ -239,7 +236,11 @@ void TaskScheduler::thread_run(int thread_id)
delete entry.task;
/* notify pool task was done */
- entry.pool->num_decrease(1);
+ {
+ /* not called from TaskPool, have to explicitly lock the mutex here */
+ thread_scoped_lock num_lock(entry.pool->num_mutex);
+ entry.pool->num_decrease(1);
+ }
}
}