29INLINE ReferenceCount::
46INLINE ReferenceCount::
64INLINE
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
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) {
330 nassertr(_ref_count > 0, 0);
342template<
class RefCountType>
345 TAU_PROFILE(
"void unref_delete(RefCountType *)",
" ", TAU_USER);
387operator
const Base &()
const {
399 "RefCountProxy<" + get_type_handle(Base).get_name() +
">",
400 get_type_handle(Base));
427#if defined(HAVE_RTTI) && !defined(__EDG__) && (!defined(__GNUC__) || defined(__GXX_RTTI))
429 std::string base_name =
typeid(Base).name();
431 std::string base_name =
"unknown";
436 ReferenceCount::init_type();
439 base_type, ReferenceCount::get_class_type());
static bool dec(Integer &var)
Atomically decrements the indicated variable and returns true if the new value is nonzero,...
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.
static void inc(Integer &var)
Atomically increments the indicated variable.
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
static void record_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently allocated.
static void remove_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently freed.
Another kind of proxy, similar to RefCountProxy.
A "proxy" to use to make a reference-countable object whenever the object cannot inherit from Referen...
A base class for all things that want to be reference-counted.
void ref() const
Explicitly increments the reference count.
WeakReferenceList * get_weak_list() const
Returns the WeakReferenceList associated with this ReferenceCount object.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
void local_object()
This function should be called, once, immediately after creating a new instance of some ReferenceCoun...
bool ref_if_nonzero() const
Atomically increases the reference count of this object if it is not zero.
bool unref_if_one() const
Atomically decreases the reference count of this object if it is one.
get_ref_count
Returns the current reference count.
virtual bool unref() const
Explicitly decrements the reference count.
WeakReferenceList * weak_ref()
Adds the indicated PointerToVoid as a weak reference to this object.
bool has_weak_list() const
Returns true if this particular ReferenceCount object has a WeakReferenceList created,...
bool test_ref_count_nonzero() const
Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
void weak_unref()
Removes the indicated PointerToVoid as a weak reference to this object.
TypeHandle is the identifier used to differentiate C++ class types.
This is an object shared by all the weak pointers that point to the same ReferenceCount object.
void ref() const
Increases the number of weak references.
bool unref() const
Decreases the number of weak references.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
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...