From 4b091f2eb69545b7ebced304b44fc197a7c2aa57 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 6 Sep 2021 17:40:53 +0200 Subject: add comments for anonymous attributes --- source/blender/blenkernel/BKE_geometry_set.hh | 4 ++++ source/blender/blenkernel/intern/anonymous_attribute.cc | 10 +++++++++- source/blender/makesdna/DNA_customdata_types.h | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index d9da4b9fb01..dd921d0d373 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -628,6 +628,10 @@ class AttributeFieldInput : public fn::FieldInput { class AnonymousAttributeFieldInput : public fn::FieldInput { private: + /** + * A strong reference is required to make sure that the referenced attribute is not removed + * automatically. + */ StrongAnonymousAttributeID anonymous_id_; public: diff --git a/source/blender/blenkernel/intern/anonymous_attribute.cc b/source/blender/blenkernel/intern/anonymous_attribute.cc index 73e2a656a7f..67611053d83 100644 --- a/source/blender/blenkernel/intern/anonymous_attribute.cc +++ b/source/blender/blenkernel/intern/anonymous_attribute.cc @@ -18,10 +18,18 @@ using namespace blender::bke; +/** + * A struct that identifies an attribute. It's lifetime is managed by an atomic reference count. + * + * Additionally, this struct can be strongly or weakly owned. The difference is that strong + * ownership means that attributes with this id will be kept around. Weak ownership just makes sure + * that the struct itself stays alive, but corresponding attributes might still be removed + * automatically. + */ struct AnonymousAttributeID { /** * Total number of references to this attribute id. Once this reaches zero, the struct can be - * freed. + * freed. This includes strong and weak references. */ mutable std::atomic refcount_tot = 0; diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 214b514b25c..6acea8da15f 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -57,7 +57,9 @@ typedef struct CustomDataLayer { void *data; /** * Run-time identifier for this layer. If no one has a strong reference to this id anymore, - * the layer can be removed. + * the layer can be removed. The custom data layer only has a weak reference to the id, because + * otherwise there will always be a strong reference and the attribute can't be removed + * automatically. */ const struct AnonymousAttributeID *anonymous_id; } CustomDataLayer; -- cgit v1.2.3