@@ -751,6 +751,79 @@ impl<T: ?Sized> Arc<T> {
751751 this. inner ( ) . strong . load ( SeqCst )
752752 }
753753
754+ /// Increments the strong reference count on the `Arc<T>` associated with the
755+ /// provided pointer by one.
756+ ///
757+ /// # Safety
758+ ///
759+ /// The pointer must have been obtained through `Arc::into_raw`, and the
760+ /// associated `Arc` instance must be valid (i.e. the strong count must be at
761+ /// least 1) for the duration of this method.
762+ ///
763+ /// # Examples
764+ ///
765+ /// ```
766+ /// #![feature(arc_mutate_strong_count)]
767+ ///
768+ /// use std::sync::Arc;
769+ ///
770+ /// let five = Arc::new(5);
771+ ///
772+ /// unsafe {
773+ /// let ptr = Arc::into_raw(five);
774+ /// Arc::incr_strong_count(ptr);
775+ ///
776+ /// // This assertion is deterministic because we haven't shared
777+ /// // the `Arc` between threads.
778+ /// let five = Arc::from_raw(ptr);
779+ /// assert_eq!(2, Arc::strong_count(&five));
780+ /// }
781+ /// ```
782+ #[ inline]
783+ #[ unstable( feature = "arc_mutate_strong_count" , issue = "71983" ) ]
784+ pub unsafe fn incr_strong_count ( ptr : * const T ) {
785+ // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
786+ let arc = mem:: ManuallyDrop :: new ( Arc :: < T > :: from_raw ( ptr) ) ;
787+ // Now increase refcount, but don't drop new refcount either
788+ let _arc_clone: mem:: ManuallyDrop < _ > = arc. clone ( ) ;
789+ }
790+
791+ /// Decrements the strong reference count on the `Arc<T>` associated with the
792+ /// provided pointer by one.
793+ ///
794+ /// # Safety
795+ ///
796+ /// The pointer must have been obtained through `Arc::into_raw`, and the
797+ /// associated `Arc` instance must be valid (i.e. the strong count must be at
798+ /// least 1) when invoking this method. This method can be used to release the final
799+ /// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
800+ /// released.
801+ ///
802+ /// # Examples
803+ ///
804+ /// ```
805+ /// #![feature(arc_mutate_strong_count)]
806+ ///
807+ /// use std::sync::Arc;
808+ ///
809+ /// let five = Arc::new(5);
810+ ///
811+ /// unsafe {
812+ /// let ptr = Arc::into_raw(five);
813+ /// Arc::decr_strong_count(ptr);
814+ ///
815+ /// // This assertion is deterministic because we haven't shared
816+ /// // the `Arc` between threads.
817+ /// let five = Arc::from_raw(ptr);
818+ /// assert_eq!(0, Arc::strong_count(&five));
819+ /// }
820+ /// ```
821+ #[ inline]
822+ #[ unstable( feature = "arc_mutate_strong_count" , issue = "71983" ) ]
823+ pub unsafe fn decr_strong_count ( ptr : * const T ) {
824+ mem:: drop ( Arc :: from_raw ( ptr) ) ;
825+ }
826+
754827 #[ inline]
755828 fn inner ( & self ) -> & ArcInner < T > {
756829 // This unsafety is ok because while this arc is alive we're guaranteed
0 commit comments