-
Notifications
You must be signed in to change notification settings - Fork 649
Cleanup #1457
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
Cleanup #1457
Conversation
} | ||
}; | ||
} | ||
#[inline] |
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.
I doubt this has any effect, since the method is always virtually dispatched.
unsafe fn increase_refcount<T: ArcWake>(data: *const()) { | ||
// Retain Arc by creating a copy | ||
let arc: Arc<T> = Arc::from_raw(data as *const T); | ||
let arc_clone = arc.clone(); | ||
// Forget the Arcs again, so that the refcount isn't decrased | ||
let _ = Arc::into_raw(arc); | ||
let _ = Arc::into_raw(arc_clone); | ||
mem::forget(arc); |
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.
I used Arc::into_raw
since that's the version where the API guarantees that it's the opposite of Arc::from_raw
.
forget will work too, but I thought if there is a more specific API available it might be nice to use it.
Anyway, both is fine.
} | ||
|
||
unsafe fn clone_arc_raw<T: ArcWake>(data: *const()) -> RawWaker { | ||
// used by `waker_ref` | ||
pub(super) unsafe fn clone_arc_raw<T: ArcWake>(data: *const()) -> RawWaker { |
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.
Where are those things exported to now? Only one level above, or even further?
It's totally to fine to use those within other parts of futures-util, but I don't think the library should publicly export these.
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.
They're just pub(super)
-- so only available to the futures_util::task module.
// Lazily create the `Arc` only when the waker is actually cloned. | ||
// FIXME: remove `transmute` when a `Waker` -> `RawWaker` conversion | ||
// function is landed in `core`. | ||
mem::transmute::<task03::Waker, RawWaker>( |
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 method on ArcWake or the same module that returns a RawWaker seems cleaner than transmute.
The ideal solution might be to directly reference and reuse a refcounted thing within Task01. But after looking up the definition of that I don't think it's possible without the extra allocation and wrapping.
Fixes some leftover bits from #1445