-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactor Waker to make unsafe parts clearer and use less unsafe #13
Conversation
This has the (maybe unintended) side effect of requiring the I think the design here was inspired by an earlier variant of Tokio's internal poll impl (But using Arc instead of custom ref-counting). There might be some improvements worth incorporating from there. |
Ah, that's a good point. Yeah, that sounds like the kind of thing that could become a performance issue. It's probably worth adding a comment explaining why. |
Using an Arc instead prevents an allocation on every clone of the waker. Instead, we only need the allocation when converting from a RefWaker to Internals. We still end up with the same number of atomic ref count changes since before we had to increment the count on the Arc<Shared> but that is no longer necessary.
I pushed a few more commits that I think improve things overall here. First is I split Second, now that we can tell from the types whether we are heap-allocated, we can make it so This makes it so that each waker has at most one heap allocation (the one where it promotes from stack allocated to heap allocated), rather than a potentially unbounded number. This means this change might make solving #14 unnecessary. |
Closing this one since it was included in #15. |
The main change here is to make
Internals.shared
anArc<Shared>
instead of a*const Shared
. This lets us avoid some unsafe casts and manually dropping.It also splits the functions in the vtable into an unsafe wrapper that casts the
this
argument and then calls a safe function that does the actual work. This is to make it clearer which steps are actually unsafe and which are safe.