-
Notifications
You must be signed in to change notification settings - Fork 66
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
Replace TrustCell implementation with atomic_refcell::AtomicRefCell #224
Replace TrustCell implementation with atomic_refcell::AtomicRefCell #224
Conversation
/// # Safety | ||
/// | ||
/// If this is used to replace the `Box<dyn Resource>` with a different one, the new one must | ||
/// have a `TypeId` that matches the one in the `ResourceId` provided here. | ||
pub unsafe fn try_fetch_internal( |
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.
Oh almost forgot!
The one other thing I did in these changes is to mark this method as unsafe
since it would otherwise allow safely swapping out the Box<dyn Resource>
stored at a particular ResourceId
with any other arbitrary Box<dyn Resource>
that doesn't necessarily correspond to the ResourceId
.
8bcc2b8
to
967a7d0
Compare
Also mark a method `unsafe` that would otherwise allow safe code to swap the trait object stored at a particular `ResourceId`.
967a7d0
to
b119397
Compare
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.
Looks good to me! Good catch on the unsafe function.
This PR replaces
TrustCell
withatomic_refcell::AtomicCell
which provides near identical functionality.Advantages of this change:
atomic_refcell
uses an alternative strategy to handle overflows of the read counter which allows for a single atomic operation when acquiring a read guard.TrustCell
implementation reduces the amount ofunsafe
code in this crate.Based on top of commits from: #223Waiting on: bholley/atomic_refcell#18