Blender  V3.3
anonymous_attribute.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
4 
5 using namespace blender::bke;
6 
20  mutable std::atomic<int> refcount_tot = 0;
21 
26  mutable std::atomic<int> refcount_strong = 0;
27 
31  std::string debug_name;
32 
36  std::string internal_name;
37 };
38 
40 static std::string get_new_internal_name()
41 {
42  static std::atomic<int> index = 0;
43  const int next_index = index.fetch_add(1);
44  return ".a_" + std::to_string(next_index);
45 }
46 
48 {
49  AnonymousAttributeID *anonymous_id = new AnonymousAttributeID();
50  anonymous_id->debug_name = debug_name;
51  anonymous_id->internal_name = get_new_internal_name();
52  anonymous_id->refcount_tot.store(1);
53  return anonymous_id;
54 }
55 
57 {
58  AnonymousAttributeID *anonymous_id = new AnonymousAttributeID();
59  anonymous_id->debug_name = debug_name;
60  anonymous_id->internal_name = get_new_internal_name();
61  anonymous_id->refcount_tot.store(1);
62  anonymous_id->refcount_strong.store(1);
63  return anonymous_id;
64 }
65 
67 {
68  return anonymous_id->refcount_strong.load() >= 1;
69 }
70 
72 {
73  anonymous_id->refcount_tot.fetch_add(1);
74 }
75 
77 {
78  anonymous_id->refcount_tot.fetch_add(1);
79  anonymous_id->refcount_strong.fetch_add(1);
80 }
81 
83 {
84  const int new_refcount = anonymous_id->refcount_tot.fetch_sub(1) - 1;
85  if (new_refcount == 0) {
86  BLI_assert(anonymous_id->refcount_strong == 0);
87  delete anonymous_id;
88  }
89 }
90 
92 {
93  anonymous_id->refcount_strong.fetch_sub(1);
95 }
96 
98 {
99  return anonymous_id->debug_name.c_str();
100 }
101 
103 {
104  return anonymous_id->internal_name.c_str();
105 }
struct AnonymousAttributeID AnonymousAttributeID
#define BLI_assert(a)
Definition: BLI_assert.h:46
void BKE_anonymous_attribute_id_decrement_weak(const AnonymousAttributeID *anonymous_id)
void BKE_anonymous_attribute_id_increment_strong(const AnonymousAttributeID *anonymous_id)
static std::string get_new_internal_name()
void BKE_anonymous_attribute_id_decrement_strong(const AnonymousAttributeID *anonymous_id)
AnonymousAttributeID * BKE_anonymous_attribute_id_new_strong(const char *debug_name)
const char * BKE_anonymous_attribute_id_internal_name(const AnonymousAttributeID *anonymous_id)
const char * BKE_anonymous_attribute_id_debug_name(const AnonymousAttributeID *anonymous_id)
void BKE_anonymous_attribute_id_increment_weak(const AnonymousAttributeID *anonymous_id)
bool BKE_anonymous_attribute_id_has_strong_references(const AnonymousAttributeID *anonymous_id)
AnonymousAttributeID * BKE_anonymous_attribute_id_new_weak(const char *debug_name)
std::string to_string(const T &n)
std::atomic< int > refcount_strong
std::atomic< int > refcount_tot