From a55039df84f53a4a3060e2a7ae84dee1dc9006ef Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Sun, 22 Nov 2020 01:04:02 +0100 Subject: [PATCH 1/2] Stabilize Arc::{incr,decr}_strong_count --- library/alloc/src/sync.rs | 18 +++++++----------- library/alloc/src/task.rs | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 9d478a302e96..1ff30ca610db 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -870,15 +870,13 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(arc_mutate_strong_count)] - /// /// use std::sync::Arc; /// /// let five = Arc::new(5); /// /// unsafe { /// let ptr = Arc::into_raw(five); - /// Arc::incr_strong_count(ptr); + /// Arc::increment_strong_count(ptr); /// /// // This assertion is deterministic because we haven't shared /// // the `Arc` between threads. @@ -887,8 +885,8 @@ impl Arc { /// } /// ``` #[inline] - #[unstable(feature = "arc_mutate_strong_count", issue = "71983")] - pub unsafe fn incr_strong_count(ptr: *const T) { + #[stable(feature = "arc_mutate_strong_count", since = "1.50.0")] + pub unsafe fn increment_strong_count(ptr: *const T) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop let arc = unsafe { mem::ManuallyDrop::new(Arc::::from_raw(ptr)) }; // Now increase refcount, but don't drop new refcount either @@ -909,27 +907,25 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(arc_mutate_strong_count)] - /// /// use std::sync::Arc; /// /// let five = Arc::new(5); /// /// unsafe { /// let ptr = Arc::into_raw(five); - /// Arc::incr_strong_count(ptr); + /// Arc::increment_strong_count(ptr); /// /// // Those assertions are deterministic because we haven't shared /// // the `Arc` between threads. /// let five = Arc::from_raw(ptr); /// assert_eq!(2, Arc::strong_count(&five)); - /// Arc::decr_strong_count(ptr); + /// Arc::decrement_strong_count(ptr); /// assert_eq!(1, Arc::strong_count(&five)); /// } /// ``` #[inline] - #[unstable(feature = "arc_mutate_strong_count", issue = "71983")] - pub unsafe fn decr_strong_count(ptr: *const T) { + #[stable(feature = "arc_mutate_strong_count", since = "1.50.0")] + pub unsafe fn decrement_strong_count(ptr: *const T) { unsafe { mem::drop(Arc::from_raw(ptr)) }; } diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index fcab3fd0badc..4ee79dae3f1a 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -60,7 +60,7 @@ impl From> for RawWaker { fn raw_waker(waker: Arc) -> RawWaker { // Increment the reference count of the arc to clone it. unsafe fn clone_waker(waker: *const ()) -> RawWaker { - unsafe { Arc::incr_strong_count(waker as *const W) }; + unsafe { Arc::increment_strong_count(waker as *const W) }; RawWaker::new( waker as *const (), &RawWakerVTable::new(clone_waker::, wake::, wake_by_ref::, drop_waker::), @@ -81,7 +81,7 @@ fn raw_waker(waker: Arc) -> RawWaker { // Decrement the reference count of the Arc on drop unsafe fn drop_waker(waker: *const ()) { - unsafe { Arc::decr_strong_count(waker as *const W) }; + unsafe { Arc::decrement_strong_count(waker as *const W) }; } RawWaker::new( From fe4ac95cb858a7a26c94c2c236fe380448675a82 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 30 Jan 2021 21:08:30 +0100 Subject: [PATCH 2/2] Bump stable version of arc_mutate_strong_count --- library/alloc/src/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 1ff30ca610db..bfb3a8858ed3 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -885,7 +885,7 @@ impl Arc { /// } /// ``` #[inline] - #[stable(feature = "arc_mutate_strong_count", since = "1.50.0")] + #[stable(feature = "arc_mutate_strong_count", since = "1.51.0")] pub unsafe fn increment_strong_count(ptr: *const T) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop let arc = unsafe { mem::ManuallyDrop::new(Arc::::from_raw(ptr)) }; @@ -924,7 +924,7 @@ impl Arc { /// } /// ``` #[inline] - #[stable(feature = "arc_mutate_strong_count", since = "1.50.0")] + #[stable(feature = "arc_mutate_strong_count", since = "1.51.0")] pub unsafe fn decrement_strong_count(ptr: *const T) { unsafe { mem::drop(Arc::from_raw(ptr)) }; }