From a833a57f6340a0b6abad71707488c953d5bb8f81 Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Thu, 28 Dec 2023 10:48:34 -0800 Subject: [PATCH] Replace `boost::intrusive_ptr` with `TfDelegatedCountPtr` for `Sdf_PathNode` --- pxr/usd/sdf/path.h | 15 +++++++-------- pxr/usd/sdf/pathNode.cpp | 40 ++++++++++++++++++++++++++++++++-------- pxr/usd/sdf/pathNode.h | 13 ++++++------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/pxr/usd/sdf/path.h b/pxr/usd/sdf/path.h index 62d414cd2d..133a0e1b43 100644 --- a/pxr/usd/sdf/path.h +++ b/pxr/usd/sdf/path.h @@ -29,12 +29,11 @@ #include "pxr/usd/sdf/pool.h" #include "pxr/usd/sdf/tokens.h" #include "pxr/base/arch/defines.h" +#include "pxr/base/tf/delegatedCountPtr.h" #include "pxr/base/tf/stl.h" #include "pxr/base/tf/token.h" #include "pxr/base/vt/traits.h" -#include - #include #include #include @@ -49,14 +48,14 @@ class Sdf_PathNode; class SdfPathAncestorsRange; // Ref-counting pointer to a path node. -// Intrusive ref-counts are used to keep the size of SdfPath +// Delegated ref-counts are used to keep the size of SdfPath // the same as a raw pointer. (shared_ptr, by comparison, // is the size of two pointers.) -typedef boost::intrusive_ptr Sdf_PathNodeConstRefPtr; +using Sdf_PathNodeConstRefPtr = TfDelegatedCountPtr; -void intrusive_ptr_add_ref(Sdf_PathNode const *); -void intrusive_ptr_release(Sdf_PathNode const *); +void TfDelegatedCountIncrement(Sdf_PathNode const *); +void TfDelegatedCountDecrement(Sdf_PathNode const *) noexcept; // Tags used for the pools of path nodes. struct Sdf_PathPrimTag; @@ -181,7 +180,7 @@ struct Sdf_PathNodeHandleImpl { inline void _AddRef(Sdf_PathNode const *p) const { if (Counted) { - intrusive_ptr_add_ref(p); + TfDelegatedCountIncrement(p); } } @@ -191,7 +190,7 @@ struct Sdf_PathNodeHandleImpl { inline void _DecRef() const { if (Counted) { - intrusive_ptr_release(get()); + TfDelegatedCountDecrement(get()); } } diff --git a/pxr/usd/sdf/pathNode.cpp b/pxr/usd/sdf/pathNode.cpp index defaf35f3e..4402c33b5f 100644 --- a/pxr/usd/sdf/pathNode.cpp +++ b/pxr/usd/sdf/pathNode.cpp @@ -765,11 +765,17 @@ Sdf_PathNode::_WriteText(Buffer &out) const } Sdf_PrimPathNode::~Sdf_PrimPathNode() { - _Remove(this, *_primNodes, GetParentNode(), _name); + _Remove(this, *_primNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _name); } Sdf_PrimPropertyPathNode::~Sdf_PrimPropertyPathNode() { - _Remove(this, *_primPropertyNodes, GetParentNode(), _name); + _Remove(this, *_primPropertyNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _name); } const TfToken & @@ -790,7 +796,10 @@ Sdf_PrimVariantSelectionNode::_WriteTextImpl(Buffer &out) const } Sdf_PrimVariantSelectionNode::~Sdf_PrimVariantSelectionNode() { - _Remove(this, *_primVarSelNodes, GetParentNode(), *_variantSelection); + _Remove(this, *_primVarSelNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + *_variantSelection); } template @@ -802,11 +811,17 @@ Sdf_TargetPathNode::_WriteTextImpl(Buffer &out) const { } Sdf_TargetPathNode::~Sdf_TargetPathNode() { - _Remove(this, *_targetNodes, GetParentNode(), _targetPath); + _Remove(this, *_targetNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _targetPath); } Sdf_RelationalAttributePathNode::~Sdf_RelationalAttributePathNode() { - _Remove(this, *_relAttrNodes, GetParentNode(), _name); + _Remove(this, *_relAttrNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _name); } template @@ -820,7 +835,10 @@ Sdf_MapperPathNode::_WriteTextImpl(Buffer &out) const { } Sdf_MapperPathNode::~Sdf_MapperPathNode() { - _Remove(this, *_mapperNodes, GetParentNode(), _targetPath); + _Remove(this, *_mapperNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _targetPath); } template @@ -830,7 +848,10 @@ Sdf_MapperArgPathNode::_WriteTextImpl(Buffer &out) const { } Sdf_MapperArgPathNode::~Sdf_MapperArgPathNode() { - _Remove(this, *_mapperArgNodes, GetParentNode(), _name); + _Remove(this, *_mapperArgNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode()), + _name); } template @@ -841,7 +862,9 @@ Sdf_ExpressionPathNode::_WriteTextImpl(Buffer &out) const { } Sdf_ExpressionPathNode::~Sdf_ExpressionPathNode() { - _Remove(this, *_expressionNodes, GetParentNode()); + _Remove(this, *_expressionNodes, + Sdf_PathNodeConstRefPtr( + TfDelegatedCountIncrementTag, GetParentNode())); } struct Sdf_Stats { @@ -867,6 +890,7 @@ _GatherChildrenFrom(Sdf_PathNode const *parent, TF_FOR_ALL(i, mapAndMutex.map) { if (i->first.parent == parent) result->emplace_back( + TfDelegatedCountIncrementTag, reinterpret_cast(i->second.GetPtr())); } } diff --git a/pxr/usd/sdf/pathNode.h b/pxr/usd/sdf/pathNode.h index 5ed72352ac..2a8dff1fa9 100644 --- a/pxr/usd/sdf/pathNode.h +++ b/pxr/usd/sdf/pathNode.h @@ -26,12 +26,11 @@ #include "pxr/pxr.h" #include "pxr/usd/sdf/api.h" +#include "pxr/base/tf/delegatedCountPtr.h" #include "pxr/base/tf/functionRef.h" #include "pxr/base/tf/token.h" #include "pxr/base/tf/mallocTag.h" -#include - PXR_NAMESPACE_OPEN_SCOPE // Sdf_PathNode @@ -245,7 +244,7 @@ class Sdf_PathNode { protected: Sdf_PathNode(Sdf_PathNode const *parent, NodeType nodeType) - : _parent(parent) + : _parent(TfDelegatedCountIncrementTag, parent) , _refCount(1) , _elementCount(parent ? parent->_elementCount + 1 : 1) , _nodeType(nodeType) @@ -299,8 +298,8 @@ class Sdf_PathNode { friend struct Sdf_PathNodePrivateAccess; // Ref-counting ops manage _refCount. - friend void intrusive_ptr_add_ref(const Sdf_PathNode*); - friend void intrusive_ptr_release(const Sdf_PathNode*); + friend void TfDelegatedCountIncrement(const Sdf_PathNode*); + friend void TfDelegatedCountDecrement(const Sdf_PathNode*) noexcept; private: static constexpr uint8_t _NodeTypeToFlags(NodeType nt) { @@ -756,10 +755,10 @@ Sdf_PathNode::GetElement() const /// Diagnostic output. SDF_API void Sdf_DumpPathStats(); -inline void intrusive_ptr_add_ref(const PXR_NS::Sdf_PathNode* p) { +inline void TfDelegatedCountIncrement(const PXR_NS::Sdf_PathNode* p) { p->_refCount.fetch_add(1, std::memory_order_relaxed); } -inline void intrusive_ptr_release(const PXR_NS::Sdf_PathNode* p) { +inline void TfDelegatedCountDecrement(const PXR_NS::Sdf_PathNode* p) noexcept { if ((p->_refCount.fetch_sub(1) & PXR_NS::Sdf_PathNode::RefCountMask) == 1) { p->_Destroy(); }