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
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-09-14 15:52:44 +0300
committerJacques Lucke <jacques@blender.org>2021-09-14 15:52:44 +0300
commitfd60f6713a9d9e6f7d706b53bf1311f2f1cd9031 (patch)
treebb762d4ce5e5ad76a52d594249e8c6ec33b08312 /source/blender/blenlib/BLI_resource_scope.hh
parent90a48fa06414ccf5fc5dd6092917413180ff30d1 (diff)
Functions: support optional outputs in multi-function
Sometimes not all outputs of a multi-function are required by the caller. In those cases it would be a waste of compute resources to calculate the unused values anyway. Now, the caller of a multi-function can specify when a specific output is not used. The called function can check if an output is unused and may ignore it. Multi-functions can still computed unused outputs as before if they don't want to check if a specific output is unused. The multi-function procedure system has been updated to support ignored outputs in call instructions. An ignored output just has no variable assigned to it. The field system has been updated to generate a multi-function procedure where unused outputs are ignored.
Diffstat (limited to 'source/blender/blenlib/BLI_resource_scope.hh')
-rw-r--r--source/blender/blenlib/BLI_resource_scope.hh11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_resource_scope.hh b/source/blender/blenlib/BLI_resource_scope.hh
index 6a98c2dcc1c..c3c0af4af50 100644
--- a/source/blender/blenlib/BLI_resource_scope.hh
+++ b/source/blender/blenlib/BLI_resource_scope.hh
@@ -137,6 +137,17 @@ class ResourceScope : NonCopyable, NonMovable {
}
/**
+ * The passed in function will be called when the scope is destructed.
+ */
+ template<typename Func> void add_destruct_call(Func func, const char *name)
+ {
+ void *buffer = m_allocator.allocate(sizeof(func), alignof(func));
+ new (buffer) Func(std::move(func));
+ this->add(
+ buffer, [](void *data) { (*(Func *)data)(); }, name);
+ }
+
+ /**
* Returns a reference to a linear allocator that is owned by the ResourcesCollector. Memory
* allocated through this allocator will be freed when the collector is destructed.
*/