[Bf-blender-cvs] [b520d46] depsgraph_refactor: Removed the users refcount and mutex from the DepsgraphScheduler.
Lukas Tönne
noreply at git.blender.org
Mon May 26 08:03:50 CEST 2014
Commit: b520d46dba1d2c0805d960d74f94ba68e879f595
Author: Lukas Tönne
Date: Sun May 25 14:54:02 2014 +0200
https://developer.blender.org/rBb520d46dba1d2c0805d960d74f94ba68e879f595
Removed the users refcount and mutex from the DepsgraphScheduler.
This was introduced by cycles to automatically disable the render
engine when it's not in use, but doesn't make a lot of sense for the
dependency graph. It adds unnecessary complexity here.
===================================================================
M source/blender/depsgraph/util/depsgraph_util_task.cpp
M source/blender/depsgraph/util/depsgraph_util_task.h
===================================================================
diff --git a/source/blender/depsgraph/util/depsgraph_util_task.cpp b/source/blender/depsgraph/util/depsgraph_util_task.cpp
index e5906be..e3005ef 100644
--- a/source/blender/depsgraph/util/depsgraph_util_task.cpp
+++ b/source/blender/depsgraph/util/depsgraph_util_task.cpp
@@ -163,7 +163,7 @@ void DepsgraphTaskPool::stop()
BLI_assert(num == 0);
}
-bool DepsgraphTaskPool::canceled()
+bool DepsgraphTaskPool::canceled() const
{
return do_cancel;
}
@@ -197,8 +197,6 @@ void DepsgraphTaskPool::num_increase()
/* Task Scheduler */
-ThreadMutex DepsgraphTaskScheduler::mutex;
-int DepsgraphTaskScheduler::users = 0;
DepsgraphTaskScheduler::Threads DepsgraphTaskScheduler::threads;
bool DepsgraphTaskScheduler::do_exit = false;
@@ -208,52 +206,33 @@ ThreadCondition DepsgraphTaskScheduler::queue_cond;
void DepsgraphTaskScheduler::init(int num_threads)
{
- BLI_mutex_lock(&mutex);
+ do_exit = false;
- /* multiple cycles instances can use this task scheduler, sharing the same
- * threads, so we keep track of the number of users. */
- if(users == 0) {
- do_exit = false;
-
- if(num_threads == 0) {
- /* automatic number of threads */
- num_threads = BLI_system_thread_count();
- }
-
- /* launch threads that will be waiting for work */
- threads.resize(num_threads);
-
- for(size_t i = 0; i < threads.size(); i++)
- threads[i] = new Thread(&DepsgraphTaskScheduler::thread_run, i);
+ if(num_threads == 0) {
+ /* automatic number of threads */
+ num_threads = BLI_system_thread_count();
}
- users++;
+ /* launch threads that will be waiting for work */
+ threads.resize(num_threads);
- BLI_mutex_unlock(&mutex);
+ for(size_t i = 0; i < threads.size(); i++)
+ threads[i] = new Thread(&DepsgraphTaskScheduler::thread_run, i);
}
void DepsgraphTaskScheduler::exit()
{
- BLI_mutex_lock(&mutex);
+ /* stop all waiting threads */
+ do_exit = true;
+ BLI_condition_notify_all(&queue_cond);
- BLI_assert(users > 0);
- users--;
-
- if(users == 0) {
- /* stop all waiting threads */
- do_exit = true;
- BLI_condition_notify_all(&queue_cond);
-
- /* delete threads */
- for (Threads::const_iterator it = threads.begin(); it != threads.end(); ++it) {
- Thread *t = *it;
- t->join();
- delete t;
- }
- threads.clear();
+ /* delete threads */
+ for (Threads::const_iterator it = threads.begin(); it != threads.end(); ++it) {
+ Thread *t = *it;
+ t->join();
+ delete t;
}
-
- BLI_mutex_unlock(&mutex);
+ threads.clear();
}
bool DepsgraphTaskScheduler::thread_wait_pop(Entry& entry)
diff --git a/source/blender/depsgraph/util/depsgraph_util_task.h b/source/blender/depsgraph/util/depsgraph_util_task.h
index 2ad0ef1..8156587 100644
--- a/source/blender/depsgraph/util/depsgraph_util_task.h
+++ b/source/blender/depsgraph/util/depsgraph_util_task.h
@@ -78,13 +78,13 @@ public:
* instead can just put the calling thread to sleep
* and let the scheduler handle tasks
*/
- void wait_work(); /* work and wait until all tasks are done */
+ void wait_work(); /* work and wait until all tasks are done */
#endif
- void wait(); /* wait until all tasks are done */
- void cancel(); /* cancel all tasks, keep worker threads running */
- void stop(); /* stop all worker threads */
+ void wait(); /* wait until all tasks are done */
+ void cancel(); /* cancel all tasks, keep worker threads running */
+ void stop(); /* stop all worker threads */
- bool canceled(); /* for worker threads, test if canceled */
+ bool canceled() const; /* for worker threads, test if canceled */
protected:
friend class DepsgraphTaskScheduler;
@@ -112,9 +112,6 @@ public:
/* number of threads that can work on task */
static int num_threads() { return threads.size(); }
- /* test if any session is using the scheduler */
- static bool active() { return users != 0; }
-
protected:
friend class DepsgraphTaskPool;
@@ -141,8 +138,6 @@ protected:
};
typedef priority_queue<Entry, std::vector<Entry>, cmp_entry> Queue;
- static ThreadMutex mutex; /* mutex for creating/freeing task pools */
- static int users; /* number of active task pools using the scheduler */
static Threads threads; /* worker threads */
static bool do_exit;
More information about the Bf-blender-cvs
mailing list