@@ -13,23 +13,6 @@ use crate::guard::Guard;
13
13
use crate :: primitive:: sync:: atomic:: AtomicUsize ;
14
14
use crossbeam_utils:: atomic:: AtomicConsume ;
15
15
16
- /// Given ordering for the success case in a compare-exchange operation, returns the strongest
17
- /// appropriate ordering for the failure case.
18
- #[ inline]
19
- fn strongest_failure_ordering ( ord : Ordering ) -> Ordering {
20
- use self :: Ordering :: * ;
21
- match ord {
22
- Relaxed | Release => Relaxed ,
23
- Acquire | AcqRel => Acquire ,
24
- _ => SeqCst ,
25
- }
26
- }
27
-
28
- /// The error returned on failed compare-and-set operation.
29
- // TODO: remove in the next major version.
30
- #[ deprecated( note = "Use `CompareExchangeError` instead" ) ]
31
- pub type CompareAndSetError < ' g , T , P > = CompareExchangeError < ' g , T , P > ;
32
-
33
16
/// The error returned on failed compare-and-swap operation.
34
17
pub struct CompareExchangeError < ' g , T : ?Sized + Pointable , P : Pointer < T > > {
35
18
/// The value in the atomic pointer at the time of the failed operation.
@@ -48,59 +31,6 @@ impl<T, P: Pointer<T> + fmt::Debug> fmt::Debug for CompareExchangeError<'_, T, P
48
31
}
49
32
}
50
33
51
- /// Memory orderings for compare-and-set operations.
52
- ///
53
- /// A compare-and-set operation can have different memory orderings depending on whether it
54
- /// succeeds or fails. This trait generalizes different ways of specifying memory orderings.
55
- ///
56
- /// The two ways of specifying orderings for compare-and-set are:
57
- ///
58
- /// 1. Just one `Ordering` for the success case. In case of failure, the strongest appropriate
59
- /// ordering is chosen.
60
- /// 2. A pair of `Ordering`s. The first one is for the success case, while the second one is
61
- /// for the failure case.
62
- // TODO: remove in the next major version.
63
- #[ deprecated(
64
- note = "`compare_and_set` and `compare_and_set_weak` that use this trait are deprecated, \
65
- use `compare_exchange` or `compare_exchange_weak instead`"
66
- ) ]
67
- pub trait CompareAndSetOrdering {
68
- /// The ordering of the operation when it succeeds.
69
- fn success ( & self ) -> Ordering ;
70
-
71
- /// The ordering of the operation when it fails.
72
- ///
73
- /// The failure ordering can't be `Release` or `AcqRel` and must be equivalent or weaker than
74
- /// the success ordering.
75
- fn failure ( & self ) -> Ordering ;
76
- }
77
-
78
- #[ allow( deprecated) ]
79
- impl CompareAndSetOrdering for Ordering {
80
- #[ inline]
81
- fn success ( & self ) -> Ordering {
82
- * self
83
- }
84
-
85
- #[ inline]
86
- fn failure ( & self ) -> Ordering {
87
- strongest_failure_ordering ( * self )
88
- }
89
- }
90
-
91
- #[ allow( deprecated) ]
92
- impl CompareAndSetOrdering for ( Ordering , Ordering ) {
93
- #[ inline]
94
- fn success ( & self ) -> Ordering {
95
- self . 0
96
- }
97
-
98
- #[ inline]
99
- fn failure ( & self ) -> Ordering {
100
- self . 1
101
- }
102
- }
103
-
104
34
/// Returns a bitmask containing the unused least significant bits of an aligned pointer to `T`.
105
35
#[ inline]
106
36
fn low_bits < T : ?Sized + Pointable > ( ) -> usize {
@@ -640,141 +570,6 @@ impl<T: ?Sized + Pointable> Atomic<T> {
640
570
Err ( prev)
641
571
}
642
572
643
- /// Stores the pointer `new` (either `Shared` or `Owned`) into the atomic pointer if the current
644
- /// value is the same as `current`. The tag is also taken into account, so two pointers to the
645
- /// same object, but with different tags, will not be considered equal.
646
- ///
647
- /// The return value is a result indicating whether the new pointer was written. On success the
648
- /// pointer that was written is returned. On failure the actual current value and `new` are
649
- /// returned.
650
- ///
651
- /// This method takes a [`CompareAndSetOrdering`] argument which describes the memory
652
- /// ordering of this operation.
653
- ///
654
- /// # Migrating to `compare_exchange`
655
- ///
656
- /// `compare_and_set` is equivalent to `compare_exchange` with the following mapping for
657
- /// memory orderings:
658
- ///
659
- /// Original | Success | Failure
660
- /// -------- | ------- | -------
661
- /// Relaxed | Relaxed | Relaxed
662
- /// Acquire | Acquire | Acquire
663
- /// Release | Release | Relaxed
664
- /// AcqRel | AcqRel | Acquire
665
- /// SeqCst | SeqCst | SeqCst
666
- ///
667
- /// # Examples
668
- ///
669
- /// ```
670
- /// # #![allow(deprecated)]
671
- /// use crossbeam_epoch::{self as epoch, Atomic, Owned, Shared};
672
- /// use std::sync::atomic::Ordering::SeqCst;
673
- ///
674
- /// let a = Atomic::new(1234);
675
- ///
676
- /// let guard = &epoch::pin();
677
- /// let curr = a.load(SeqCst, guard);
678
- /// let res1 = a.compare_and_set(curr, Shared::null(), SeqCst, guard);
679
- /// let res2 = a.compare_and_set(curr, Owned::new(5678), SeqCst, guard);
680
- /// # unsafe { drop(curr.into_owned()); } // avoid leak
681
- /// ```
682
- // TODO: remove in the next major version.
683
- #[ allow( deprecated) ]
684
- #[ deprecated( note = "Use `compare_exchange` instead" ) ]
685
- pub fn compare_and_set < ' g , O , P > (
686
- & self ,
687
- current : Shared < ' _ , T > ,
688
- new : P ,
689
- ord : O ,
690
- guard : & ' g Guard ,
691
- ) -> Result < Shared < ' g , T > , CompareAndSetError < ' g , T , P > >
692
- where
693
- O : CompareAndSetOrdering ,
694
- P : Pointer < T > ,
695
- {
696
- self . compare_exchange ( current, new, ord. success ( ) , ord. failure ( ) , guard)
697
- }
698
-
699
- /// Stores the pointer `new` (either `Shared` or `Owned`) into the atomic pointer if the current
700
- /// value is the same as `current`. The tag is also taken into account, so two pointers to the
701
- /// same object, but with different tags, will not be considered equal.
702
- ///
703
- /// Unlike [`compare_and_set`], this method is allowed to spuriously fail even when comparison
704
- /// succeeds, which can result in more efficient code on some platforms. The return value is a
705
- /// result indicating whether the new pointer was written. On success the pointer that was
706
- /// written is returned. On failure the actual current value and `new` are returned.
707
- ///
708
- /// This method takes a [`CompareAndSetOrdering`] argument which describes the memory
709
- /// ordering of this operation.
710
- ///
711
- /// [`compare_and_set`]: Atomic::compare_and_set
712
- ///
713
- /// # Migrating to `compare_exchange_weak`
714
- ///
715
- /// `compare_and_set_weak` is equivalent to `compare_exchange_weak` with the following mapping for
716
- /// memory orderings:
717
- ///
718
- /// Original | Success | Failure
719
- /// -------- | ------- | -------
720
- /// Relaxed | Relaxed | Relaxed
721
- /// Acquire | Acquire | Acquire
722
- /// Release | Release | Relaxed
723
- /// AcqRel | AcqRel | Acquire
724
- /// SeqCst | SeqCst | SeqCst
725
- ///
726
- /// # Examples
727
- ///
728
- /// ```
729
- /// # #![allow(deprecated)]
730
- /// use crossbeam_epoch::{self as epoch, Atomic, Owned, Shared};
731
- /// use std::sync::atomic::Ordering::SeqCst;
732
- ///
733
- /// let a = Atomic::new(1234);
734
- /// let guard = &epoch::pin();
735
- ///
736
- /// let mut new = Owned::new(5678);
737
- /// let mut ptr = a.load(SeqCst, guard);
738
- /// # unsafe { drop(a.load(SeqCst, guard).into_owned()); } // avoid leak
739
- /// loop {
740
- /// match a.compare_and_set_weak(ptr, new, SeqCst, guard) {
741
- /// Ok(p) => {
742
- /// ptr = p;
743
- /// break;
744
- /// }
745
- /// Err(err) => {
746
- /// ptr = err.current;
747
- /// new = err.new;
748
- /// }
749
- /// }
750
- /// }
751
- ///
752
- /// let mut curr = a.load(SeqCst, guard);
753
- /// loop {
754
- /// match a.compare_and_set_weak(curr, Shared::null(), SeqCst, guard) {
755
- /// Ok(_) => break,
756
- /// Err(err) => curr = err.current,
757
- /// }
758
- /// }
759
- /// # unsafe { drop(curr.into_owned()); } // avoid leak
760
- /// ```
761
- // TODO: remove in the next major version.
762
- #[ allow( deprecated) ]
763
- #[ deprecated( note = "Use `compare_exchange_weak` instead" ) ]
764
- pub fn compare_and_set_weak < ' g , O , P > (
765
- & self ,
766
- current : Shared < ' _ , T > ,
767
- new : P ,
768
- ord : O ,
769
- guard : & ' g Guard ,
770
- ) -> Result < Shared < ' g , T > , CompareAndSetError < ' g , T , P > >
771
- where
772
- O : CompareAndSetOrdering ,
773
- P : Pointer < T > ,
774
- {
775
- self . compare_exchange_weak ( current, new, ord. success ( ) , ord. failure ( ) , guard)
776
- }
777
-
778
573
/// Bitwise "and" with the current tag.
779
574
///
780
575
/// Performs a bitwise "and" operation on the current tag and the argument `val`, and sets the
0 commit comments