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
path: root/intern
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-04-01 16:23:08 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-04-01 16:25:35 +0300
commitf318e8322f2e339ce6e918fca9146334f84f6990 (patch)
treec1374eb0c2bcfe6e4e53e72d0374ec3c3051bf22 /intern
parentc6b27dd4fa02b2609a18ce3aa9c71b64e12b500d (diff)
Cycles: Report thread ID from worker thread to callbacks
Main use case of this ID will be to emulate TLS which otherwise would require having some platform-specific implementations which is not always really optimal. See notes about the argument in util_task.h.
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/util/util_task.cpp10
-rw-r--r--intern/cycles/util/util_task.h16
2 files changed, 20 insertions, 6 deletions
diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp
index 5523f373824..28bbc8856c6 100644
--- a/intern/cycles/util/util_task.cpp
+++ b/intern/cycles/util/util_task.cpp
@@ -89,7 +89,7 @@ void TaskPool::wait_work()
/* if found task, do it, otherwise wait until other tasks are done */
if(found_entry) {
/* run task */
- work_entry.task->run();
+ work_entry.task->run(0);
/* delete task */
delete work_entry.task;
@@ -192,7 +192,7 @@ void TaskScheduler::init(int num_threads)
threads.resize(num_threads);
for(size_t i = 0; i < threads.size(); i++)
- threads[i] = new thread(function_bind(&TaskScheduler::thread_run, i));
+ threads[i] = new thread(function_bind(&TaskScheduler::thread_run, i + 1));
}
users++;
@@ -243,7 +243,7 @@ bool TaskScheduler::thread_wait_pop(Entry& entry)
return true;
}
-void TaskScheduler::thread_run(int /*thread_id*/)
+void TaskScheduler::thread_run(int thread_id)
{
Entry entry;
@@ -252,7 +252,7 @@ void TaskScheduler::thread_run(int /*thread_id*/)
/* keep popping off tasks */
while(thread_wait_pop(entry)) {
/* run task */
- entry.task->run();
+ entry.task->run(thread_id);
/* delete task */
delete entry.task;
@@ -419,7 +419,7 @@ void DedicatedTaskPool::thread_run()
/* keep popping off tasks */
while(thread_wait_pop(task)) {
/* run task */
- task->run();
+ task->run(0);
/* delete task */
delete task;
diff --git a/intern/cycles/util/util_task.h b/intern/cycles/util/util_task.h
index a8e1963252a..2ce26fa7103 100644
--- a/intern/cycles/util/util_task.h
+++ b/intern/cycles/util/util_task.h
@@ -27,7 +27,21 @@ class Task;
class TaskPool;
class TaskScheduler;
-typedef function<void(void)> TaskRunFunction;
+/* Notes on Thread ID
+ *
+ * Thread ID argument reports the 0-based ID of a working thread from which
+ * the run() callback is being invoked. Thread ID of 0 denotes the thread from
+ * which wait_work() was called.
+ *
+ * DO NOT use this ID to control execution flaw, use it only for things like
+ * emulating TLS which does not affect on scheduling. Don't use this ID to make
+ * any decisions.
+ *
+ * It is to be noted here that dedicated task pool will always report thread ID
+ * of 0.
+ */
+
+typedef function<void(int thread_id)> TaskRunFunction;
/* Task
*