[Bf-blender-cvs] [f318e832] master: Cycles: Report thread ID from worker thread to callbacks

Sergey Sharybin noreply at git.blender.org
Fri Apr 1 15:25:14 CEST 2016


Commit: f318e8322f2e339ce6e918fca9146334f84f6990
Author: Sergey Sharybin
Date:   Fri Apr 1 15:23:08 2016 +0200
Branches: master
https://developer.blender.org/rBf318e8322f2e339ce6e918fca9146334f84f6990

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.

===================================================================

M	intern/cycles/util/util_task.cpp
M	intern/cycles/util/util_task.h

===================================================================

diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp
index 5523f37..28bbc88 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 a8e1963..2ce26fa 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
  *




More information about the Bf-blender-cvs mailing list