7#ifndef PXR_BASE_TF_REF_BASE_H
8#define PXR_BASE_TF_REF_BASE_H
15#include "pxr/base/tf/api.h"
20PXR_NAMESPACE_OPEN_SCOPE
59 typedef void (*UniqueChangedFuncPtr)(
TfRefBase const *, bool);
60 struct UniqueChangedListener {
62 UniqueChangedFuncPtr func;
84 return std::abs(_refCount.load(std::memory_order_relaxed));
92 void SetShouldInvokeUniqueChangedListener(
bool shouldCall) {
93 int curValue = _refCount.load(std::memory_order_relaxed);
94 while ((curValue > 0 && shouldCall) ||
95 (curValue < 0 && !shouldCall)) {
96 if (_refCount.compare_exchange_weak(curValue, -curValue)) {
102 TF_API
static void SetUniqueChangedListener(UniqueChangedListener listener);
112 std::atomic_int &_GetRefCount()
const {
119 mutable std::atomic_int _refCount;
121 static UniqueChangedListener _uniqueChangedListener;
122 template <
typename T>
friend class TfRefPtr;
123 friend struct Tf_RefPtr_UniqueChangedCounter;
124 friend struct Tf_RefPtr_Counter;
144PXR_NAMESPACE_CLOSE_SCOPE
Enable a concrete base class for use with TfRefPtr.
friend TfRefPtr< T > TfCreateRefPtrFromProtectedWeakPtr(TfWeakPtr< T > const &)
Thread-safe creation of a Tf ref pointer from a Tf weak pointer.
bool IsUnique() const
Return true if only one TfRefPtr points to this object.
size_t GetCurrentCount() const
Return the current reference count of this object.
Reference-counted smart pointer utility class.
Enable a concrete base class for use with TfRefPtr that inhibits the "unique changed" facility of TfR...
Pointer storage with deletion detection.