@@ -1575,6 +1575,41 @@ assert_eq!(foo.load(Ordering::SeqCst), 10);
1575
1575
}
1576
1576
}
1577
1577
1578
+ doc_comment! {
1579
+ concat!( "Subtracts from the given atomic value, returning the previous value.
1580
+
1581
+ This operation wraps around on overflow.
1582
+
1583
+ `fetch_sub_explicit` takes " , stringify!( $atomic_type) , " which will be substracted by given value
1584
+ in respect to [`Ordering`] argument which describes the memory ordering
1585
+ of this operation. All ordering modes are possible. Note that using
1586
+ [`Acquire`] makes the store part of this operation [`Relaxed`], and
1587
+ using [`Release`] makes the load part [`Relaxed`].
1588
+
1589
+ [`Ordering`]: enum.Ordering.html
1590
+ [`Relaxed`]: enum.Ordering.html#variant.Relaxed
1591
+ [`Release`]: enum.Ordering.html#variant.Release
1592
+ [`Acquire`]: enum.Ordering.html#variant.Acquire
1593
+
1594
+ # Examples
1595
+
1596
+ ```
1597
+ " , $extra_feature, "use std::sync::atomic::{" , stringify!( $atomic_type) , ", Ordering};
1598
+
1599
+ let foo = " , stringify!( $atomic_type) , "::new(20);
1600
+ assert_eq!(" , stringify!( $atomic_type) , ".fetch_sub_explicit(foo, Ordering::SeqCst), 20);
1601
+ assert_eq!(foo.load(Ordering::SeqCst), 10);
1602
+ ```" ) ,
1603
+ #[ inline]
1604
+ #[ $stable]
1605
+ #[ cfg( target_has_atomic = "cas" ) ]
1606
+ pub fn fetch_sub_explicit( f: * const $atomic_type,
1607
+ val: $int_type,
1608
+ order: Ordering ) -> $int_type {
1609
+ unsafe { atomic_sub( ( * f) . v. get( ) , val, order) }
1610
+ }
1611
+ }
1612
+
1578
1613
doc_comment! {
1579
1614
concat!( "Bitwise \" and\" with the current value.
1580
1615
0 commit comments