@@ -305,6 +305,7 @@ impl<T> Atomic<T> {
305
305
/// use crossbeam_epoch::Atomic;
306
306
///
307
307
/// let a = Atomic::new(1234);
308
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
308
309
/// ```
309
310
pub fn new ( init : T ) -> Atomic < T > {
310
311
Self :: init ( init)
@@ -320,6 +321,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
320
321
/// use crossbeam_epoch::Atomic;
321
322
///
322
323
/// let a = Atomic::<i32>::init(1234);
324
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
323
325
/// ```
324
326
pub fn init ( init : T :: Init ) -> Atomic < T > {
325
327
Self :: from ( Owned :: init ( init) )
@@ -373,6 +375,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
373
375
/// let a = Atomic::new(1234);
374
376
/// let guard = &epoch::pin();
375
377
/// let p = a.load(SeqCst, guard);
378
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
376
379
/// ```
377
380
pub fn load < ' g > ( & self , ord : Ordering , _: & ' g Guard ) -> Shared < ' g , T > {
378
381
unsafe { Shared :: from_usize ( self . data . load ( ord) ) }
@@ -398,6 +401,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
398
401
/// let a = Atomic::new(1234);
399
402
/// let guard = &epoch::pin();
400
403
/// let p = a.load_consume(guard);
404
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
401
405
/// ```
402
406
pub fn load_consume < ' g > ( & self , _: & ' g Guard ) -> Shared < ' g , T > {
403
407
unsafe { Shared :: from_usize ( self . data . load_consume ( ) ) }
@@ -415,8 +419,10 @@ impl<T: ?Sized + Pointable> Atomic<T> {
415
419
/// use std::sync::atomic::Ordering::SeqCst;
416
420
///
417
421
/// let a = Atomic::new(1234);
422
+ /// # unsafe { drop(a.load(SeqCst, &crossbeam_epoch::pin()).into_owned()); } // avoid leak
418
423
/// a.store(Shared::null(), SeqCst);
419
424
/// a.store(Owned::new(1234), SeqCst);
425
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
420
426
/// ```
421
427
pub fn store < P : Pointer < T > > ( & self , new : P , ord : Ordering ) {
422
428
self . data . store ( new. into_usize ( ) , ord) ;
@@ -437,6 +443,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
437
443
/// let a = Atomic::new(1234);
438
444
/// let guard = &epoch::pin();
439
445
/// let p = a.swap(Shared::null(), SeqCst, guard);
446
+ /// # unsafe { drop(p.into_owned()); } // avoid leak
440
447
/// ```
441
448
pub fn swap < ' g , P : Pointer < T > > ( & self , new : P , ord : Ordering , _: & ' g Guard ) -> Shared < ' g , T > {
442
449
unsafe { Shared :: from_usize ( self . data . swap ( new. into_usize ( ) , ord) ) }
@@ -471,6 +478,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
471
478
/// let curr = a.load(SeqCst, guard);
472
479
/// let res1 = a.compare_exchange(curr, Shared::null(), SeqCst, SeqCst, guard);
473
480
/// let res2 = a.compare_exchange(curr, Owned::new(5678), SeqCst, SeqCst, guard);
481
+ /// # unsafe { drop(curr.into_owned()); } // avoid leak
474
482
/// ```
475
483
pub fn compare_exchange < ' g , P > (
476
484
& self ,
@@ -526,6 +534,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
526
534
///
527
535
/// let mut new = Owned::new(5678);
528
536
/// let mut ptr = a.load(SeqCst, guard);
537
+ /// # unsafe { drop(a.load(SeqCst, guard).into_owned()); } // avoid leak
529
538
/// loop {
530
539
/// match a.compare_exchange_weak(ptr, new, SeqCst, SeqCst, guard) {
531
540
/// Ok(p) => {
@@ -546,6 +555,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
546
555
/// Err(err) => curr = err.current,
547
556
/// }
548
557
/// }
558
+ /// # unsafe { drop(curr.into_owned()); } // avoid leak
549
559
/// ```
550
560
pub fn compare_exchange_weak < ' g , P > (
551
561
& self ,
@@ -608,6 +618,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
608
618
///
609
619
/// let res2 = a.fetch_update(SeqCst, SeqCst, guard, |x| None);
610
620
/// assert!(res2.is_err());
621
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
611
622
/// ```
612
623
pub fn fetch_update < ' g , F > (
613
624
& self ,
@@ -666,6 +677,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
666
677
/// let curr = a.load(SeqCst, guard);
667
678
/// let res1 = a.compare_and_set(curr, Shared::null(), SeqCst, guard);
668
679
/// let res2 = a.compare_and_set(curr, Owned::new(5678), SeqCst, guard);
680
+ /// # unsafe { drop(curr.into_owned()); } // avoid leak
669
681
/// ```
670
682
// TODO: remove in the next major version.
671
683
#[ allow( deprecated) ]
@@ -723,6 +735,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
723
735
///
724
736
/// let mut new = Owned::new(5678);
725
737
/// let mut ptr = a.load(SeqCst, guard);
738
+ /// # unsafe { drop(a.load(SeqCst, guard).into_owned()); } // avoid leak
726
739
/// loop {
727
740
/// match a.compare_and_set_weak(ptr, new, SeqCst, guard) {
728
741
/// Ok(p) => {
@@ -743,6 +756,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
743
756
/// Err(err) => curr = err.current,
744
757
/// }
745
758
/// }
759
+ /// # unsafe { drop(curr.into_owned()); } // avoid leak
746
760
/// ```
747
761
// TODO: remove in the next major version.
748
762
#[ allow( deprecated) ]
@@ -925,6 +939,7 @@ impl<T: ?Sized + Pointable> From<Owned<T>> for Atomic<T> {
925
939
/// use crossbeam_epoch::{Atomic, Owned};
926
940
///
927
941
/// let a = Atomic::<i32>::from(Owned::new(1234));
942
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
928
943
/// ```
929
944
fn from ( owned : Owned < T > ) -> Self {
930
945
let data = owned. data ;
@@ -1108,6 +1123,7 @@ impl<T: ?Sized + Pointable> Owned<T> {
1108
1123
/// let o = Owned::new(1234);
1109
1124
/// let guard = &epoch::pin();
1110
1125
/// let p = o.into_shared(guard);
1126
+ /// # unsafe { drop(p.into_owned()); } // avoid leak
1111
1127
/// ```
1112
1128
#[ allow( clippy:: needless_lifetimes) ]
1113
1129
pub fn into_shared < ' g > ( self , _: & ' g Guard ) -> Shared < ' g , T > {
@@ -1291,6 +1307,7 @@ impl<'g, T> Shared<'g, T> {
1291
1307
/// let guard = &epoch::pin();
1292
1308
/// let p = a.load(SeqCst, guard);
1293
1309
/// assert_eq!(p.as_raw(), raw);
1310
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1294
1311
/// ```
1295
1312
pub fn as_raw ( & self ) -> * const T {
1296
1313
let ( raw, _) = decompose_tag :: < T > ( self . data ) ;
@@ -1329,6 +1346,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1329
1346
/// assert!(a.load(SeqCst, guard).is_null());
1330
1347
/// a.store(Owned::new(1234), SeqCst);
1331
1348
/// assert!(!a.load(SeqCst, guard).is_null());
1349
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1332
1350
/// ```
1333
1351
pub fn is_null ( & self ) -> bool {
1334
1352
let ( raw, _) = decompose_tag :: < T > ( self . data ) ;
@@ -1365,6 +1383,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1365
1383
/// unsafe {
1366
1384
/// assert_eq!(p.deref(), &1234);
1367
1385
/// }
1386
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1368
1387
/// ```
1369
1388
pub unsafe fn deref ( & self ) -> & ' g T {
1370
1389
let ( raw, _) = decompose_tag :: < T > ( self . data ) ;
@@ -1406,6 +1425,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1406
1425
/// unsafe {
1407
1426
/// assert_eq!(p.deref(), &vec![1, 2, 3, 4, 5]);
1408
1427
/// }
1428
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1409
1429
/// ```
1410
1430
pub unsafe fn deref_mut ( & mut self ) -> & ' g mut T {
1411
1431
let ( raw, _) = decompose_tag :: < T > ( self . data ) ;
@@ -1442,6 +1462,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1442
1462
/// unsafe {
1443
1463
/// assert_eq!(p.as_ref(), Some(&1234));
1444
1464
/// }
1465
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1445
1466
/// ```
1446
1467
pub unsafe fn as_ref ( & self ) -> Option < & ' g T > {
1447
1468
let ( raw, _) = decompose_tag :: < T > ( self . data ) ;
@@ -1493,6 +1514,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1493
1514
/// let guard = &epoch::pin();
1494
1515
/// let p = a.load(SeqCst, guard);
1495
1516
/// assert_eq!(p.tag(), 2);
1517
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1496
1518
/// ```
1497
1519
pub fn tag ( & self ) -> usize {
1498
1520
let ( _, tag) = decompose_tag :: < T > ( self . data ) ;
@@ -1516,6 +1538,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
1516
1538
/// assert_eq!(p1.tag(), 0);
1517
1539
/// assert_eq!(p2.tag(), 2);
1518
1540
/// assert_eq!(p1.as_raw(), p2.as_raw());
1541
+ /// # unsafe { drop(a.into_owned()); } // avoid leak
1519
1542
/// ```
1520
1543
pub fn with_tag ( & self , tag : usize ) -> Shared < ' g , T > {
1521
1544
unsafe { Self :: from_usize ( compose_tag :: < T > ( self . data , tag) ) }
@@ -1536,6 +1559,7 @@ impl<T> From<*const T> for Shared<'_, T> {
1536
1559
///
1537
1560
/// let p = Shared::from(Box::into_raw(Box::new(1234)) as *const _);
1538
1561
/// assert!(!p.is_null());
1562
+ /// # unsafe { drop(p.into_owned()); } // avoid leak
1539
1563
/// ```
1540
1564
fn from ( raw : * const T ) -> Self {
1541
1565
let raw = raw as usize ;
0 commit comments