about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2021-01-31 01:47:20 +0100
committerGitHub <noreply@github.com>2021-01-31 01:47:20 +0100
commitac37c326aeccb5710f18235b18015750e6484d66 (patch)
tree6e6f9bb456b8d3550d03d5812c036453331a2d5d /library/alloc/src
parent1bf130519ca1c020623a550dc6b250eacea68e72 (diff)
parentfe4ac95cb858a7a26c94c2c236fe380448675a82 (diff)
downloadrust-ac37c326aeccb5710f18235b18015750e6484d66.tar.gz
rust-ac37c326aeccb5710f18235b18015750e6484d66.zip
Rollup merge of #79285 - yoshuawuyts:stabilize-arc_mutate_strong_count, r=m-ou-se
Stabilize Arc::{increment,decrement}_strong_count

Tracking issue: https://github.com/rust-lang/rust/issues/71983

Stabilizes `Arc::{incr,decr}_strong_count`, enabling unsafely incrementing an decrementing the Arc strong count directly with fewer gotchas. This API was first introduced on nightly six months ago, and has not seen any changes since. The initial PR showed two existing pieces of code that would benefit from this API, and included a change inside the stdlib to use this.

Given the small surface area, predictable use, and no changes since introduction, I'd like to propose we stabilize this.

closes https://github.com/rust-lang/rust/issues/71983
r? `@Mark-Simulacrum`

## Links
 * [Initial implementation](https://github.com/rust-lang/rust/pull/70733)
 * [Motivation from #68700](https://github.com/rust-lang/rust/pull/68700#discussion_r396169064)
 * [Real world example in an executor](https://docs.rs/extreme/666.666.666666/src/extreme/lib.rs.html#13)
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/sync.rs18
-rw-r--r--library/alloc/src/task.rs4
2 files changed, 9 insertions, 13 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs
index d0081097fe1..461ca85c030 100644
--- a/library/alloc/src/sync.rs
+++ b/library/alloc/src/sync.rs
@@ -962,15 +962,13 @@ impl<T: ?Sized> Arc<T> {
     /// # 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.
@@ -979,8 +977,8 @@ impl<T: ?Sized> Arc<T> {
     /// }
     /// ```
     #[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.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::<T>::from_raw(ptr)) };
         // Now increase refcount, but don't drop new refcount either
@@ -1001,27 +999,25 @@ impl<T: ?Sized> Arc<T> {
     /// # 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.51.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 69690494196..a80550a9653 100644
--- a/library/alloc/src/task.rs
+++ b/library/alloc/src/task.rs
@@ -62,7 +62,7 @@ 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 {
-        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::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
@@ -83,7 +83,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 ()) {
-        unsafe { Arc::decr_strong_count(waker as *const W) };
+        unsafe { Arc::decrement_strong_count(waker as *const W) };
     }
 
     RawWaker::new(