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:
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.
*/