[Bf-blender-cvs] [b37093de7b4] master: BLI: add C++ wrapper for task isolation

Jacques Lucke noreply at git.blender.org
Wed Jun 16 16:29:31 CEST 2021


Commit: b37093de7b42cf331a4ae5830737d9972d7bb426
Author: Jacques Lucke
Date:   Wed Jun 16 16:29:21 2021 +0200
Branches: master
https://developer.blender.org/rBb37093de7b42cf331a4ae5830737d9972d7bb426

BLI: add C++ wrapper for task isolation

This makes it easier to use task isolation in c++ code.
Previously, one either had to check `WITH_TBB` (possibly indirectly
through `WITH_OPENVDB`) or one had to use the C function which
is less convenient.

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

M	source/blender/blenkernel/intern/volume.cc
M	source/blender/blenlib/BLI_task.hh

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

diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 41f0b5c6b72..5e444e66a15 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -36,6 +36,7 @@
 #include "BLI_math.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
+#include "BLI_task.hh"
 #include "BLI_utildefines.h"
 
 #include "BKE_anim_data.h"
@@ -325,9 +326,8 @@ struct VolumeGrid {
     openvdb::io::File file(filepath);
 
     /* Isolate file loading since that's potentially multithreaded and we are
-     * holding a mutex lock. See BLI_task_isolate. Note OpenVDB already uses
-     * TBB, so it's fine to use here without a wrapper. */
-    tbb::this_task_arena::isolate([&] {
+     * holding a mutex lock. */
+    blender::threading::isolate_task([&] {
       try {
         file.setCopyMaxBytes(0);
         file.open();
diff --git a/source/blender/blenlib/BLI_task.hh b/source/blender/blenlib/BLI_task.hh
index cdf7759ef41..5f5a17f6b58 100644
--- a/source/blender/blenlib/BLI_task.hh
+++ b/source/blender/blenlib/BLI_task.hh
@@ -31,6 +31,7 @@
 #  include <tbb/blocked_range.h>
 #  include <tbb/parallel_for.h>
 #  include <tbb/parallel_for_each.h>
+#  include <tbb/task_arena.h>
 #  ifdef WIN32
 /* We cannot keep this defined, since other parts of the code deal with this on their own, leading
  * to multiple define warnings unless we un-define this, however we can only undefine this if we
@@ -75,4 +76,14 @@ void parallel_for(IndexRange range, int64_t grain_size, const Function &function
 #endif
 }
 
+/** See #BLI_task_isolate for a description of what isolating a task means. */
+template<typename Function> void isolate_task(const Function &function)
+{
+#ifdef WITH_TBB
+  tbb::this_task_arena::isolate(function);
+#else
+  function();
+#endif
+}
+
 }  // namespace blender::threading



More information about the Bf-blender-cvs mailing list