From be55ce42fa81b72e3e3677c1b062019dd4b56ac6 Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Thu, 28 Dec 2023 10:51:06 -0800 Subject: [PATCH] Replace `boost::intrusive_ptr` with `TfDelegatedCountPtr` in `Usd_Shared` --- pxr/usd/usd/shared.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pxr/usd/usd/shared.h b/pxr/usd/usd/shared.h index d8ccd9b495..d869fd80ad 100644 --- a/pxr/usd/usd/shared.h +++ b/pxr/usd/usd/shared.h @@ -26,9 +26,9 @@ #include "pxr/pxr.h" #include "pxr/usd/usd/api.h" +#include "pxr/base/tf/delegatedCountPtr.h" #include "pxr/base/tf/hash.h" -#include #include PXR_NAMESPACE_OPEN_SCOPE @@ -42,11 +42,11 @@ struct Usd_Counted { explicit Usd_Counted(T &&data) : data(std::move(data)), count(0) {} friend inline void - intrusive_ptr_add_ref(Usd_Counted const *c) { + TfDelegatedCountIncrement(Usd_Counted const *c) { c->count.fetch_add(1, std::memory_order_relaxed); } friend inline void - intrusive_ptr_release(Usd_Counted const *c) { + TfDelegatedCountDecrement(Usd_Counted const *c) { if (c->count.fetch_sub(1, std::memory_order_release) == 1) { std::atomic_thread_fence(std::memory_order_acquire); delete c; @@ -66,11 +66,13 @@ template struct Usd_Shared { // Construct a Usd_Shared with a value-initialized T instance. - Usd_Shared() : _held(new Usd_Counted()) {} + Usd_Shared() : _held(TfMakeDelegatedCountPtr>()) {} // Create a copy of \p obj. - explicit Usd_Shared(T const &obj) : _held(new Usd_Counted(obj)) {} + explicit Usd_Shared(T const &obj) : + _held(TfMakeDelegatedCountPtr>(obj)) {} // Move from \p obj. - explicit Usd_Shared(T &&obj) : _held(new Usd_Counted(std::move(obj))) {} + explicit Usd_Shared(T &&obj) : + _held(TfMakeDelegatedCountPtr>(std::move(obj))) {} // Create an empty shared, which may not be accessed via Get(), // GetMutable(), IsUnique(), Clone(), or MakeUnique(). This is useful when @@ -86,7 +88,7 @@ struct Usd_Shared // Return true if no other Usd_Shared instance shares this instance's data. bool IsUnique() const { return _held->count == 1; } // Make a new copy of the held data and refer to it. - void Clone() { _held.reset(new Usd_Counted(Get())); } + void Clone() { _held = TfMakeDelegatedCountPtr>(Get()); } // Ensure this Usd_Shared instance has unique data. Equivalent to: // \code // if (not shared.IsUnique()) { shared.Clone(); } @@ -108,7 +110,7 @@ struct Usd_Shared return TfHash()(sh._held->data); } private: - boost::intrusive_ptr> _held; + TfDelegatedCountPtr> _held; };