29 INLINE ReferenceCount::
33 #ifdef DO_MEMORY_USAGE 46 INLINE ReferenceCount::
50 #ifdef DO_MEMORY_USAGE 64 INLINE
void ReferenceCount::
72 nassertv(_ref_count != deleted_ref_count);
80 TAU_PROFILE(
"ReferenceCount::~ReferenceCount()",
" ", TAU_USER);
87 nassertv(_ref_count != deleted_ref_count);
93 nassertv(_ref_count <= local_ref_count);
97 nassertv(_ref_count >= 0);
108 nassertv(_ref_count == 0 || _ref_count == local_ref_count);
111 if (_weak_list !=
nullptr) {
113 _weak_list =
nullptr;
120 _ref_count = deleted_ref_count;
123 #ifdef DO_MEMORY_USAGE 131 INLINE
int ReferenceCount::
132 get_ref_count()
const {
152 TAU_PROFILE(
"void ReferenceCount::ref()",
" ", TAU_USER);
180 TAU_PROFILE(
"void ReferenceCount::unref()",
" ", TAU_USER);
187 nassertr(_ref_count > 0, 0);
199 return do_test_ref_count_integrity();
212 return do_test_ref_count_nonzero();
232 nassertv(_ref_count == 0);
234 _ref_count = local_ref_count;
245 return _weak_list !=
nullptr;
272 TAU_PROFILE(
"void ReferenceCount::weak_ref()",
" ", TAU_USER);
276 nassertr(_ref_count != deleted_ref_count,
nullptr);
289 TAU_PROFILE(
"void ReferenceCount::weak_unref()",
" ", TAU_USER);
294 nassertv(weak_list !=
nullptr);
295 bool nonzero = weak_list->
unref();
310 AtomicAdjust::Integer ref_count;
313 if (ref_count <= 0) {
327 template<
class RefCountType>
330 TAU_PROFILE(
"void unref_delete(RefCountType *)",
" ", TAU_USER);
372 operator
const Base &()
const {
384 "RefCountProxy<" + get_type_handle(Base).get_name() +
">",
385 get_type_handle(Base));
412 #if defined(HAVE_RTTI) && !defined(__EDG__) 414 std::string base_name =
typeid(Base).name();
416 std::string base_name =
"unknown";
421 ReferenceCount::init_type();
424 base_type, ReferenceCount::get_class_type());
bool test_ref_count_nonzero() const
Does some easy checks to make sure that the reference count isn't zero, or completely bogus...
void ref() const
Increases the number of weak references.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(), along with zero to four record_derivation()s.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
static ALWAYS_INLINE Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.
This is an object shared by all the weak pointers that point to the same ReferenceCount object...
bool has_weak_list() const
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
void weak_unref()
Removes the indicated PointerToVoid as a weak reference to this object.
static void remove_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently freed.
void ref() const
Explicitly increments the reference count.
static ALWAYS_INLINE Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
WeakReferenceList * weak_ref()
Adds the indicated PointerToVoid as a weak reference to this object.
void local_object()
This function should be called, once, immediately after creating a new instance of some ReferenceCoun...
A base class for all things that want to be reference-counted.
bool ref_if_nonzero() const
Atomically increases the reference count of this object if it is not zero.
static ALWAYS_INLINE void inc(Integer &var)
Atomically increments the indicated variable.
static ALWAYS_INLINE bool dec(Integer &var)
Atomically decrements the indicated variable and returns true if the new value is nonzero...
Another kind of proxy, similar to RefCountProxy.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
TypeHandle is the identifier used to differentiate C++ class types.
TypeHandle register_dynamic_type(const std::string &name)
This is essentially similar to register_type(), except that it doesn't store a reference to any TypeH...
static ALWAYS_INLINE Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
A "proxy" to use to make a reference-countable object whenever the object cannot inherit from Referen...
static void record_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently allocated.
virtual bool unref() const
Explicitly decrements the reference count.
WeakReferenceList * get_weak_list() const
Returns the WeakReferenceList associated with this ReferenceCount object.
bool unref() const
Decreases the number of weak references.