A base class for all things that want to be reference-counted. More...
#include "referenceCount.h"
Public Member Functions | |
int | get_ref_count () const |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | ref_if_nonzero () const |
Atomically increases the reference count of this object if it is not zero. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
WeakReferenceList * | weak_ref () |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref () |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes | |
get_ref_count | |
Returns the current reference count. More... | |
A base class for all things that want to be reference-counted.
ReferenceCount works in conjunction with PointerTo to automatically delete objects when the last pointer to them goes away.
Definition at line 38 of file referenceCount.h.
|
inline |
Returns the WeakReferenceList associated with this ReferenceCount object.
If there has never been a WeakReferenceList associated with this object, creates one now.
The returned object will be deleted automatically when all weak and strong references to the object have gone.
Definition at line 257 of file referenceCount.I.
References AtomicAdjustDummyImpl::get_ptr().
|
inline |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
In general, this will be true if there was ever a WeakPointerTo created for this object (even if there is not any for it now).
Definition at line 244 of file referenceCount.I.
|
inline |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.
This allows the object to be passed to functions that will increment and decrement the object's reference count temporarily, and it will prevent the object from being deleted (inappropriately), when the reference count returns to zero. It actually achieves this by setting a large positive value in the reference count field.
Definition at line 229 of file referenceCount.I.
Referenced by AsyncTaskManager::find_task(), AsyncTaskManager::find_tasks(), and AsyncTaskManager::find_tasks_matching().
|
inline |
Explicitly increments the reference count.
User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.
This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.
Definition at line 151 of file referenceCount.I.
|
inline |
Atomically increases the reference count of this object if it is not zero.
Do not use this. This exists only to implement a special case for weak pointers.
Definition at line 306 of file referenceCount.I.
References AtomicAdjustDummyImpl::compare_and_exchange(), AtomicAdjustDummyImpl::get(), and test_ref_count_integrity().
|
inline |
Does some easy checks to make sure that the reference count isn't completely bogus.
Returns true if ok, false otherwise.
Definition at line 197 of file referenceCount.I.
Referenced by EggGroupNode::add_child(), InternalName::find_ancestor(), InternalName::get_ancestor(), InternalName::get_top(), ref_if_nonzero(), and split_vertex().
|
inline |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
Returns true if ok, false otherwise.
Definition at line 210 of file referenceCount.I.
|
inlinevirtual |
Explicitly decrements the reference count.
Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic.) However, see the helper function unref_delete().
User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.
This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.
The return value is true if the new reference count is nonzero, false if it is zero.
Reimplemented in TransformState, RenderState, RenderEffects, RenderAttrib, GeomVertexArrayFormat, GeomVertexFormat, and InternalName.
Definition at line 179 of file referenceCount.I.
Referenced by RenderEffect::finalize(), Texture::finalize(), NodeReferenceCount::node_unref(), NodeCachedReferenceCount::node_unref(), InternalName::unref(), GeomVertexFormat::unref(), and GeomVertexArrayFormat::unref().
|
inline |
Adds the indicated PointerToVoid as a weak reference to this object.
Returns an object that will persist as long as any reference (strong or weak) exists, for calling unref() or checking whether the object still exists.
Definition at line 271 of file referenceCount.I.
|
inline |
Removes the indicated PointerToVoid as a weak reference to this object.
It must have previously been added via a call to weak_ref().
Definition at line 288 of file referenceCount.I.
|
inline |
Returns the current reference count.
Definition at line 53 of file referenceCount.h.
Referenced by RenderState::list_cycles().