diff options
author | Carl Lerche <me@carllerche.com> | 2020-03-05 10:31:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-05 10:31:37 -0800 |
commit | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 (patch) | |
tree | c88e547d6913b204f590aea54dc03328ee3cb094 /tokio/src/sync/notify.rs | |
parent | 5ede2e4d6b2f732e83e33f9693682dffc6c9f5b0 (diff) |
rt: cleanup and simplify scheduler (scheduler v2.5) (#2273)
A refactor of the scheduler internals focusing on simplifying and
reducing unsafety. There are no fundamental logic changes.
* The state transitions of the core task component are refined and
reduced.
* `basic_scheduler` has most unsafety removed.
* `local_set` has most unsafety removed.
* `threaded_scheduler` limits most unsafety to its queue implementation.
Diffstat (limited to 'tokio/src/sync/notify.rs')
-rw-r--r-- | tokio/src/sync/notify.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tokio/src/sync/notify.rs b/tokio/src/sync/notify.rs index ef34ad2d..56b1c9a8 100644 --- a/tokio/src/sync/notify.rs +++ b/tokio/src/sync/notify.rs @@ -306,10 +306,10 @@ fn notify_locked(waiters: &mut LinkedList<Waiter>, state: &AtomicU8, curr: u8) - // transition **out** of `WAITING`. // // Get a pending waiter - let waiter = waiters.pop_back().unwrap(); + let mut waiter = waiters.pop_back().unwrap(); // Safety: `waiters` lock is still held. - let waiter = unsafe { &mut *waiter }; + let waiter = unsafe { waiter.as_mut() }; assert!(!waiter.notified); @@ -423,7 +423,9 @@ impl Future for Notified<'_> { } // Insert the waiter into the linked list - waiters.push_front(waiter.get()); + // + // safety: pointers from `UnsafeCell` are never null. + waiters.push_front(unsafe { NonNull::new_unchecked(waiter.get()) }); *state = Waiting; } @@ -535,16 +537,15 @@ impl Drop for Notified<'_> { /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waiter { - type Handle = *mut Waiter; + type Handle = NonNull<Waiter>; type Target = Waiter; - fn to_raw(handle: *mut Waiter) -> NonNull<Waiter> { - debug_assert!(!handle.is_null()); - unsafe { NonNull::new_unchecked(handle) } + fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> { + *handle } - unsafe fn from_raw(ptr: NonNull<Waiter>) -> *mut Waiter { - ptr.as_ptr() + unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { + ptr } unsafe fn pointers(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { |