Stabilize Arc::{incr,decr}_strong_count
This commit is contained in:
parent
6340607aca
commit
a55039df84
2 changed files with 9 additions and 13 deletions
|
@ -870,15 +870,13 @@ impl<T: ?Sized> Arc<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(arc_mutate_strong_count)]
|
|
||||||
///
|
|
||||||
/// use std::sync::Arc;
|
/// use std::sync::Arc;
|
||||||
///
|
///
|
||||||
/// let five = Arc::new(5);
|
/// let five = Arc::new(5);
|
||||||
///
|
///
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// let ptr = Arc::into_raw(five);
|
/// 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
|
/// // This assertion is deterministic because we haven't shared
|
||||||
/// // the `Arc` between threads.
|
/// // the `Arc` between threads.
|
||||||
|
@ -887,8 +885,8 @@ impl<T: ?Sized> Arc<T> {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
|
#[stable(feature = "arc_mutate_strong_count", since = "1.50.0")]
|
||||||
pub unsafe fn incr_strong_count(ptr: *const T) {
|
pub unsafe fn increment_strong_count(ptr: *const T) {
|
||||||
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
|
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
|
||||||
let arc = unsafe { mem::ManuallyDrop::new(Arc::<T>::from_raw(ptr)) };
|
let arc = unsafe { mem::ManuallyDrop::new(Arc::<T>::from_raw(ptr)) };
|
||||||
// Now increase refcount, but don't drop new refcount either
|
// Now increase refcount, but don't drop new refcount either
|
||||||
|
@ -909,27 +907,25 @@ impl<T: ?Sized> Arc<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(arc_mutate_strong_count)]
|
|
||||||
///
|
|
||||||
/// use std::sync::Arc;
|
/// use std::sync::Arc;
|
||||||
///
|
///
|
||||||
/// let five = Arc::new(5);
|
/// let five = Arc::new(5);
|
||||||
///
|
///
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// let ptr = Arc::into_raw(five);
|
/// 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
|
/// // Those assertions are deterministic because we haven't shared
|
||||||
/// // the `Arc` between threads.
|
/// // the `Arc` between threads.
|
||||||
/// let five = Arc::from_raw(ptr);
|
/// let five = Arc::from_raw(ptr);
|
||||||
/// assert_eq!(2, Arc::strong_count(&five));
|
/// assert_eq!(2, Arc::strong_count(&five));
|
||||||
/// Arc::decr_strong_count(ptr);
|
/// Arc::decrement_strong_count(ptr);
|
||||||
/// assert_eq!(1, Arc::strong_count(&five));
|
/// assert_eq!(1, Arc::strong_count(&five));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
|
#[stable(feature = "arc_mutate_strong_count", since = "1.50.0")]
|
||||||
pub unsafe fn decr_strong_count(ptr: *const T) {
|
pub unsafe fn decrement_strong_count(ptr: *const T) {
|
||||||
unsafe { mem::drop(Arc::from_raw(ptr)) };
|
unsafe { mem::drop(Arc::from_raw(ptr)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
|
||||||
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
|
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
|
||||||
// Increment the reference count of the arc to clone it.
|
// Increment the reference count of the arc to clone it.
|
||||||
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
|
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(
|
RawWaker::new(
|
||||||
waker as *const (),
|
waker as *const (),
|
||||||
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
|
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
|
||||||
|
@ -81,7 +81,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
|
||||||
|
|
||||||
// Decrement the reference count of the Arc on drop
|
// Decrement the reference count of the Arc on drop
|
||||||
unsafe fn drop_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) {
|
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(
|
RawWaker::new(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue