diff options
Diffstat (limited to 'src/liballoc/task.rs')
| -rw-r--r-- | src/liballoc/task.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/liballoc/task.rs b/src/liballoc/task.rs index a64d5d7a63b..745444a152e 100644 --- a/src/liballoc/task.rs +++ b/src/liballoc/task.rs @@ -1,6 +1,6 @@ #![unstable(feature = "wake_trait", issue = "69912")] //! Types and Traits for working with asynchronous tasks. -use core::mem::{self, ManuallyDrop}; +use core::mem::ManuallyDrop; use core::task::{RawWaker, RawWakerVTable, Waker}; use crate::sync::Arc; @@ -60,9 +60,11 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker { fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker { // Increment the reference count of the arc to clone it. unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker { - let waker: Arc<W> = Arc::from_raw(waker as *const W); - mem::forget(Arc::clone(&waker)); - raw_waker(waker) + Arc::incr_strong_count(waker as *const W); + RawWaker::new( + waker as *const (), + &RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>), + ) } // Wake by value, moving the Arc into the Wake::wake function @@ -79,7 +81,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker { // Decrement the reference count of the Arc on drop unsafe fn drop_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) { - mem::drop(Arc::from_raw(waker as *const W)); + Arc::decr_strong_count(waker as *const W); } RawWaker::new( |
