Skip to content

Commit

Permalink
Replace boost::intrusive_ptr with TfDelegatedCountPtr in `Usd_Cra…
Browse files Browse the repository at this point in the history
…teFile`
  • Loading branch information
nvmkuruc committed Jan 22, 2024
1 parent 8552493 commit addce5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pxr/usd/usd/crateFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ ::_AddRangeReference(void const *addr, size_t numBytes)
// If we take the source's count from 0 -> 1, add a reference to the
// mapping.
if (iresult.first->NewRef()) {
intrusive_ptr_add_ref(this);
TfDelegatedCountIncrement(this);
}
return &(*iresult.first);
}
Expand Down Expand Up @@ -562,7 +562,7 @@ bool CrateFile::_FileMapping::_Impl::ZeroCopySource::operator==(
void CrateFile::_FileMapping::_Impl::ZeroCopySource::_Detached(
Vt_ArrayForeignDataSource *selfBase) {
auto *self = static_cast<ZeroCopySource *>(selfBase);
intrusive_ptr_release(self->_mapping);
TfDelegatedCountDecrement(self->_mapping);
}

template <class FileMappingPtr>
Expand Down
16 changes: 8 additions & 8 deletions pxr/usd/usd/crateFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "crateValueInliners.h"

#include "pxr/base/arch/fileSystem.h"
#include "pxr/base/tf/delegatedCountPtr.h"
#include "pxr/base/tf/hash.h"
#include "pxr/base/tf/pxrTslRobinMap/robin_map.h"
#include "pxr/base/tf/token.h"
Expand All @@ -44,8 +45,6 @@
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/sdf/types.h"

#include <boost/intrusive_ptr.hpp>

#include <tbb/concurrent_unordered_set.h>
#include <tbb/spin_rw_mutex.h>

Expand Down Expand Up @@ -403,15 +402,15 @@ class CrateFile
// other code reading/writing the file.)
void _DetachReferencedRanges();

// This class is managed by a combination of boost::intrusive_ptr
// This class is managed by a combination of TfDelegatedCountPtr
// and manual reference counting -- see explicit calls to
// intrusive_ptr_add_ref/release in the .cpp file.
// TfDelegatedCount{Increment,Decrement} in the .cpp file.
friend inline void
intrusive_ptr_add_ref(_Impl const *m) {
TfDelegatedCountIncrement(_Impl const *m) {
m->_refCount.fetch_add(1, std::memory_order_relaxed);
}
friend inline void
intrusive_ptr_release(_Impl const *m) {
TfDelegatedCountDecrement(_Impl const *m) {
if (m->_refCount.fetch_sub(1, std::memory_order_release) == 1) {
std::atomic_thread_fence(std::memory_order_acquire);
delete m;
Expand All @@ -432,7 +431,8 @@ class CrateFile
// Construct with new mapping.
explicit _FileMapping(ArchConstFileMapping &&mapping,
int64_t offset=0, int64_t length=-1) noexcept
: _impl(new _Impl(std::move(mapping), offset, length)) {}
: _impl(TfDelegatedCountIncrementTag,
new _Impl(std::move(mapping), offset, length)) {}

_FileMapping(_FileMapping &&other) noexcept
: _impl(std::move(other._impl)) {
Expand Down Expand Up @@ -477,7 +477,7 @@ class CrateFile
}

private:
boost::intrusive_ptr<_Impl> _impl;
TfDelegatedCountPtr<_Impl> _impl;
};

////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit addce5e

Please sign in to comment.