[Bf-blender-cvs] [4e5a328e556] master: Tasks: support build with TBB version 2017

Brecht Van Lommel noreply at git.blender.org
Tue May 5 14:26:15 CEST 2020


Commit: 4e5a328e556109162b81ec3a388988375a91b0d9
Author: Brecht Van Lommel
Date:   Mon May 4 23:59:58 2020 +0200
Branches: master
https://developer.blender.org/rB4e5a328e556109162b81ec3a388988375a91b0d9

Tasks: support build with TBB version 2017

Make the task pool implementation compatible with older versions that are
used by install_deps.sh.

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

M	source/blender/blenlib/intern/task_pool.cc
M	source/blender/blenlib/intern/task_scheduler.cc

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

diff --git a/source/blender/blenlib/intern/task_pool.cc b/source/blender/blenlib/intern/task_pool.cc
index b0d7df92343..b97db30d64f 100644
--- a/source/blender/blenlib/intern/task_pool.cc
+++ b/source/blender/blenlib/intern/task_pool.cc
@@ -72,7 +72,10 @@ class Task {
     }
   }
 
-  /* Move constructor. */
+  /* Move constructor.
+   * For performance, ensure we never copy the task and only move it.
+   * For TBB version 2017 and earlier we apply a workaround to make up for
+   * the lack of move constructor support. */
   Task(Task &&other)
       : pool(other.pool),
         run(other.run),
@@ -87,16 +90,32 @@ class Task {
     other.freedata = NULL;
   }
 
-  /* Execute task. */
-  void operator()() const
+#if defined(WITH_TBB) && TBB_INTERFACE_VERSION_MAJOR < 10
+  Task(const Task &other)
+      : pool(other.pool),
+        run(other.run),
+        taskdata(other.taskdata),
+        free_taskdata(other.free_taskdata),
+        freedata(other.freedata)
   {
-    run(pool, taskdata);
+    ((Task &)other).pool = NULL;
+    ((Task &)other).run = NULL;
+    ((Task &)other).taskdata = NULL;
+    ((Task &)other).free_taskdata = false;
+    ((Task &)other).freedata = NULL;
   }
-
-  /* For performance, ensure we never copy the task and only move it. */
+#else
   Task(const Task &other) = delete;
+#endif
+
   Task &operator=(const Task &other) = delete;
   Task &operator=(Task &&other) = delete;
+
+  /* Execute task. */
+  void operator()() const
+  {
+    run(pool, taskdata);
+  }
 };
 
 /* TBB Task Group.
diff --git a/source/blender/blenlib/intern/task_scheduler.cc b/source/blender/blenlib/intern/task_scheduler.cc
index 682fee5c46d..325056d41ee 100644
--- a/source/blender/blenlib/intern/task_scheduler.cc
+++ b/source/blender/blenlib/intern/task_scheduler.cc
@@ -29,18 +29,21 @@
 /* Quiet top level deprecation message, unrelated to API usage here. */
 #  define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
 #  include <tbb/tbb.h>
+#  if TBB_INTERFACE_VERSION_MAJOR >= 10
+#    define WITH_TBB_GLOBAL_CONTROL
+#  endif
 #endif
 
 /* Task Scheduler */
 
 static int task_scheduler_num_threads = 1;
-#ifdef WITH_TBB
+#ifdef WITH_TBB_GLOBAL_CONTROL
 static tbb::global_control *task_scheduler_global_control = nullptr;
 #endif
 
 void BLI_task_scheduler_init()
 {
-#ifdef WITH_TBB
+#ifdef WITH_TBB_GLOBAL_CONTROL
   const int num_threads_override = BLI_system_num_threads_override_get();
 
   if (num_threads_override > 0) {
@@ -57,12 +60,14 @@ void BLI_task_scheduler_init()
      * at all. */
     task_scheduler_num_threads = BLI_system_thread_count();
   }
+#else
+  task_scheduler_num_threads = BLI_system_thread_count();
 #endif
 }
 
 void BLI_task_scheduler_exit()
 {
-#ifdef WITH_TBB
+#ifdef WITH_TBB_GLOBAL_CONTROL
   OBJECT_GUARDED_DELETE(task_scheduler_global_control, tbb::global_control);
 #endif
 }



More information about the Bf-blender-cvs mailing list