@@ -470,6 +470,44 @@ impl<T> Atomic<T> {
470
470
pub fn fetch_xor < ' g > ( & self , val : usize , ord : Ordering , _: & ' g Guard ) -> Shared < ' g , T > {
471
471
unsafe { Shared :: from_usize ( self . data . fetch_xor ( val & low_bits :: < T > ( ) , ord) ) }
472
472
}
473
+
474
+ /// Takes ownership of the pointee.
475
+ ///
476
+ /// This consumes the atomic and converts it into [`Owned`]. As [`Atomic`] doesn't have a
477
+ /// destructor and doesn't drop the pointee while [`Owned`] does, this is suitable for
478
+ /// destructors of data structures.
479
+ ///
480
+ /// # Panics
481
+ ///
482
+ /// Panics if this pointer is null, but only in debug mode.
483
+ ///
484
+ /// # Safety
485
+ ///
486
+ /// This method may be called only if the pointer is valid and nobody else is holding a
487
+ /// reference to the same object.
488
+ ///
489
+ /// # Examples
490
+ ///
491
+ /// ```rust
492
+ /// # use std::mem;
493
+ /// # use crossbeam_epoch::Atomic;
494
+ /// struct DataStructure {
495
+ /// ptr: Atomic<usize>,
496
+ /// }
497
+ ///
498
+ /// impl Drop for DataStructure {
499
+ /// fn drop(&mut self) {
500
+ /// // By now the DataStructure lives only in our thread and we are sure we don't hold
501
+ /// // any Shared or & to it ourselves.
502
+ /// unsafe {
503
+ /// drop(mem::replace(&mut self.ptr, Atomic::null()).into_owned());
504
+ /// }
505
+ /// }
506
+ /// }
507
+ /// ```
508
+ pub unsafe fn into_owned ( self ) -> Owned < T > {
509
+ Owned :: from_usize ( self . data . into_inner ( ) )
510
+ }
473
511
}
474
512
475
513
impl < T > fmt:: Debug for Atomic < T > {
0 commit comments