diff --git a/tokio/src/runtime/park.rs b/tokio/src/runtime/park.rs index 2392846ab..97e14fb2a 100644 --- a/tokio/src/runtime/park.rs +++ b/tokio/src/runtime/park.rs @@ -222,7 +222,6 @@ impl UnparkThread { use crate::loom::thread::AccessError; use std::future::Future; use std::marker::PhantomData; -use std::mem; use std::rc::Rc; use std::task::{RawWaker, RawWakerVTable, Waker}; @@ -317,16 +316,12 @@ unsafe fn unparker_to_raw_waker(unparker: Arc) -> RawWaker { } unsafe fn clone(raw: *const ()) -> RawWaker { - let unparker = Inner::from_raw(raw); - - // Increment the ref count - mem::forget(unparker.clone()); - - unparker_to_raw_waker(unparker) + Arc::increment_strong_count(raw as *const Inner); + unparker_to_raw_waker(Inner::from_raw(raw)) } unsafe fn drop_waker(raw: *const ()) { - let _ = Inner::from_raw(raw); + drop(Inner::from_raw(raw)); } unsafe fn wake(raw: *const ()) { @@ -335,11 +330,8 @@ unsafe fn wake(raw: *const ()) { } unsafe fn wake_by_ref(raw: *const ()) { - let unparker = Inner::from_raw(raw); - unparker.unpark(); - - // We don't actually own a reference to the unparker - mem::forget(unparker); + let raw = raw as *const Inner; + (*raw).unpark(); } #[cfg(loom)] diff --git a/tokio/src/runtime/tests/mod.rs b/tokio/src/runtime/tests/mod.rs index b12a76e26..56699998c 100644 --- a/tokio/src/runtime/tests/mod.rs +++ b/tokio/src/runtime/tests/mod.rs @@ -63,7 +63,7 @@ cfg_loom! { // Make sure debug assertions are enabled #[cfg(not(debug_assertions))] - compiler_error!("these tests require debug assertions to be enabled"); + compile_error!("these tests require debug assertions to be enabled"); } cfg_not_loom! { diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index 4b5989597..13d462666 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -1,6 +1,5 @@ use crate::sync::Notify; use std::future::Future; -use std::mem::ManuallyDrop; use std::sync::Arc; use std::task::{Context, RawWaker, RawWakerVTable, Waker}; @@ -12,16 +11,16 @@ fn notify_clones_waker_before_lock() { const VTABLE: &RawWakerVTable = &RawWakerVTable::new(clone_w, wake, wake_by_ref, drop_w); unsafe fn clone_w(data: *const ()) -> RawWaker { - let arc = ManuallyDrop::new(Arc::::from_raw(data as *const Notify)); + let ptr = data as *const Notify; + Arc::::increment_strong_count(ptr); // Or some other arbitrary code that shouldn't be executed while the // Notify wait list is locked. - arc.notify_one(); - let _arc_clone: ManuallyDrop<_> = arc.clone(); + (*ptr).notify_one(); RawWaker::new(data, VTABLE) } unsafe fn drop_w(data: *const ()) { - let _ = Arc::::from_raw(data as *const Notify); + drop(Arc::::from_raw(data as *const Notify)); } unsafe fn wake(_data: *const ()) { diff --git a/tokio/src/util/wake.rs b/tokio/src/util/wake.rs index 5526cbc63..c872ce5d6 100644 --- a/tokio/src/util/wake.rs +++ b/tokio/src/util/wake.rs @@ -50,16 +50,8 @@ fn waker_vtable() -> &'static RawWakerVTable { ) } -unsafe fn inc_ref_count(data: *const ()) { - // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = ManuallyDrop::new(Arc::::from_raw(data as *const T)); - - // Now increase refcount, but don't drop new refcount either - let _arc_clone: ManuallyDrop<_> = arc.clone(); -} - unsafe fn clone_arc_raw(data: *const ()) -> RawWaker { - inc_ref_count::(data); + Arc::::increment_strong_count(data as *const T); RawWaker::new(data, waker_vtable::()) }