-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TfDelegatedCountPtr
to support custom bookkeeping
#2891
Conversation
b227f2c
to
49d6d18
Compare
Filed as internal issue #USD-9122 |
49d6d18
to
730d079
Compare
755d12d
to
8552493
Compare
Tf_TrackingPtr
to support custom bookkeepingTfDelegatedCountPtr
to support custom bookkeeping
fbe72b6
to
5715c18
Compare
pxr/base/tf/delegatedCountPtr.h
Outdated
} | ||
|
||
/// Dereference the underlying pointer | ||
ReferenceType operator*() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noexcept
?
pxr/base/tf/delegatedCountPtr.h
Outdated
/// construction, assignment, and destruction operations. | ||
/// | ||
/// `TfDelegatedCountIncrement` and `TfDelegatedCountDecrement` are expected to | ||
/// be `noexcept`. The increment and decrement methods can assume pointers are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring these to be noexcept
seems potentially too restrictive to me... What's the motivation for this requirement? Could we just transparently propagate the noexcept
-ness of these so that it's a "pay for what you use" type of thing?
5d8db81
to
147c677
Compare
147c677
to
1efa3c7
Compare
pxr/base/tf/delegatedCountPtr.h
Outdated
/// construction, assignment, and destruction operations. | ||
/// | ||
/// As it may be called in a destructor, `TfDelegatedCountDecrement` is expected | ||
/// to be `noexcept`. The increment and decrement methods can assume pointers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this comment now, no?
pxr/base/tf/delegatedCountPtr.h
Outdated
|
||
using IncrementIsNoExcept = | ||
std::integral_constant< | ||
bool, noexcept(TfDelegatedCountIncrement(RawPtrType{}))>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use std::declval<RawPtrType>()
for the value here?
pxr/base/tf/delegatedCountPtr.h
Outdated
} | ||
|
||
/// Dereference the underlying pointer | ||
ReferenceType operator*() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be noexcept
I think.
/// | ||
/// `ptr` will be reset to its default state (ie. `nullptr`). | ||
TfDelegatedCountPtr& operator=(TfDelegatedCountPtr&& ptr) | ||
noexcept(DecrementIsNoExcept()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok if I had a foo
that was a TfDelegatedCountPtr<Foo>
and I did:
foo = std::move(foo);
That would blow up, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a test case for this specifically. It doesn't blow up. foo
is left in a valid state. See TestMovingSelf()
.
pxr/base/tf/delegatedCountPtr.h
Outdated
|
||
private: | ||
void _IncrementIfValid() noexcept(IncrementIsNoExcept()) { | ||
if (get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to just do if (_pointer)
here? we use it directly in the body immediately after -- it seems clearer to me that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of prior usages of _pointer
had to be converted to get()
to support operations on convertible types without friend
-ship. But there's no reason this usage had to be converted.
9bcaf2c
to
e64b2a5
Compare
e64b2a5
to
56678ce
Compare
Description of Change(s)
OpenUSD currently uses
boost::intrusive_ptr
to support customized bookkeeping of types. Specialization is achieved through ADL (intrusive_ptr_add_ref
andintrusive_ptr_release
).This introduces
TfDelegatedCountPtr
as an alternative to support customized bookkeeping via ADL overloadsTfDelegatedCountIncrement
andTfDelegatedCountDecrement
.The
TfDelegatedCountPtr
avoids implicit conversion of raw pointers and requires explicit tag dispatch to specify whether the pointer should be retained or not.This also provides a
TfMakeDelegatedCountPtr
creator function to avoid direct allocation.Fixes Issue(s)