@@ -64,10 +64,10 @@ pub trait Atomic: Send + Sync {
6464 fn set ( & self , val : Self :: T ) ;
6565 /// Get the value.
6666 fn get ( & self ) -> Self :: T ;
67- /// Increment the value by a given amount.
68- fn inc_by ( & self , delta : Self :: T ) ;
69- /// Decrement the value by a given amount.
70- fn dec_by ( & self , delta : Self :: T ) ;
67+ /// Increment the value by a given amount returning the old value .
68+ fn inc_by ( & self , delta : Self :: T ) -> Self :: T ;
69+ /// Decrement the value by a given amount returning the old value .
70+ fn dec_by ( & self , delta : Self :: T ) -> Self :: T ;
7171}
7272
7373/// A atomic float.
@@ -106,7 +106,7 @@ impl Atomic for AtomicF64 {
106106 }
107107
108108 #[ inline]
109- fn inc_by ( & self , delta : Self :: T ) {
109+ fn inc_by ( & self , delta : Self :: T ) -> Self :: T {
110110 loop {
111111 let current = self . inner . load ( Ordering :: Acquire ) ;
112112 let new = u64_to_f64 ( current) + delta;
@@ -117,14 +117,14 @@ impl Atomic for AtomicF64 {
117117 Ordering :: Relaxed ,
118118 ) ;
119119 if result. is_ok ( ) {
120- return ;
120+ return u64_to_f64 ( current ) ;
121121 }
122122 }
123123 }
124124
125125 #[ inline]
126- fn dec_by ( & self , delta : Self :: T ) {
127- self . inc_by ( -delta) ;
126+ fn dec_by ( & self , delta : Self :: T ) -> Self :: T {
127+ self . inc_by ( -delta)
128128 }
129129}
130130
@@ -161,13 +161,13 @@ impl Atomic for AtomicI64 {
161161 }
162162
163163 #[ inline]
164- fn inc_by ( & self , delta : Self :: T ) {
165- self . inner . fetch_add ( delta, Ordering :: Relaxed ) ;
164+ fn inc_by ( & self , delta : Self :: T ) -> Self :: T {
165+ self . inner . fetch_add ( delta, Ordering :: Relaxed )
166166 }
167167
168168 #[ inline]
169- fn dec_by ( & self , delta : Self :: T ) {
170- self . inner . fetch_sub ( delta, Ordering :: Relaxed ) ;
169+ fn dec_by ( & self , delta : Self :: T ) -> Self :: T {
170+ self . inner . fetch_sub ( delta, Ordering :: Relaxed )
171171 }
172172}
173173
@@ -197,13 +197,13 @@ impl Atomic for AtomicU64 {
197197 }
198198
199199 #[ inline]
200- fn inc_by ( & self , delta : Self :: T ) {
201- self . inc_by_with_ordering ( delta, Ordering :: Relaxed ) ;
200+ fn inc_by ( & self , delta : Self :: T ) -> Self :: T {
201+ self . inc_by_with_ordering ( delta, Ordering :: Relaxed )
202202 }
203203
204204 #[ inline]
205- fn dec_by ( & self , delta : Self :: T ) {
206- self . inner . fetch_sub ( delta, Ordering :: Relaxed ) ;
205+ fn dec_by ( & self , delta : Self :: T ) -> Self :: T {
206+ self . inner . fetch_sub ( delta, Ordering :: Relaxed )
207207 }
208208}
209209
@@ -229,14 +229,19 @@ impl AtomicU64 {
229229 }
230230
231231 /// Increment the value by a given amount with the provided memory ordering.
232- pub fn inc_by_with_ordering ( & self , delta : u64 , ordering : Ordering ) {
233- self . inner . fetch_add ( delta, ordering) ;
232+ pub fn inc_by_with_ordering ( & self , delta : u64 , ordering : Ordering ) -> u64 {
233+ self . inner . fetch_add ( delta, ordering)
234234 }
235235
236236 /// Stores a value into the atomic integer, returning the previous value.
237237 pub fn swap ( & self , val : u64 , ordering : Ordering ) -> u64 {
238238 self . inner . swap ( val, ordering)
239239 }
240+
241+ /// Returns a reference to the inner atomic u64
242+ pub fn inner ( & self ) -> & StdAtomicU64 {
243+ & self . inner
244+ }
240245}
241246
242247#[ cfg( test) ]
0 commit comments