24#ifndef PXR_BASE_TF_REF_BASE_H
25#define PXR_BASE_TF_REF_BASE_H
32#include "pxr/base/tf/api.h"
37PXR_NAMESPACE_OPEN_SCOPE
76 typedef void (*UniqueChangedFuncPtr)(
TfRefBase const *, bool);
77 struct UniqueChangedListener {
79 UniqueChangedFuncPtr func;
101 return std::abs(_refCount.load(std::memory_order_relaxed));
109 void SetShouldInvokeUniqueChangedListener(
bool shouldCall) {
110 int curValue = _refCount.load(std::memory_order_relaxed);
111 while ((curValue > 0 && shouldCall) ||
112 (curValue < 0 && !shouldCall)) {
113 if (_refCount.compare_exchange_weak(curValue, -curValue)) {
119 TF_API
static void SetUniqueChangedListener(UniqueChangedListener listener);
129 std::atomic_int &_GetRefCount()
const {
136 mutable std::atomic_int _refCount;
138 static UniqueChangedListener _uniqueChangedListener;
139 template <
typename T>
friend class TfRefPtr;
140 friend struct Tf_RefPtr_UniqueChangedCounter;
141 friend struct Tf_RefPtr_Counter;
161PXR_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.