Skip to content

Commit f6cc11b

Browse files
committed
Auto merge of #40927 - stjepang:docs-atomic-overflow-note, r=alexcrichton
Add a note about overflow for fetch_add/fetch_sub Fixes #40916 Fixes #34618 r? @steveklabnik
2 parents 5e122f5 + 2946c41 commit f6cc11b

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/libcore/sync/atomic.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl AtomicBool {
321321
}
322322
}
323323

324-
/// Stores a value into the bool, returning the old value.
324+
/// Stores a value into the bool, returning the previous value.
325325
///
326326
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
327327
/// of this operation.
@@ -732,7 +732,7 @@ impl<T> AtomicPtr<T> {
732732
}
733733
}
734734

735-
/// Stores a value into the pointer, returning the old value.
735+
/// Stores a value into the pointer, returning the previous value.
736736
///
737737
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
738738
/// of this operation.
@@ -1047,7 +1047,7 @@ macro_rules! atomic_int {
10471047
unsafe { atomic_store(self.v.get(), val, order); }
10481048
}
10491049

1050-
/// Stores a value into the atomic integer, returning the old value.
1050+
/// Stores a value into the atomic integer, returning the previous value.
10511051
///
10521052
/// `swap` takes an [`Ordering`] argument which describes the memory ordering of this
10531053
/// operation.
@@ -1201,7 +1201,9 @@ macro_rules! atomic_int {
12011201
}
12021202
}
12031203

1204-
/// Add to the current value, returning the previous value.
1204+
/// Adds to the current value, returning the previous value.
1205+
///
1206+
/// This operation wraps around on overflow.
12051207
///
12061208
/// # Examples
12071209
///
@@ -1218,7 +1220,9 @@ macro_rules! atomic_int {
12181220
unsafe { atomic_add(self.v.get(), val, order) }
12191221
}
12201222

1221-
/// Subtract from the current value, returning the previous value.
1223+
/// Subtracts from the current value, returning the previous value.
1224+
///
1225+
/// This operation wraps around on overflow.
12221226
///
12231227
/// # Examples
12241228
///
@@ -1235,7 +1239,12 @@ macro_rules! atomic_int {
12351239
unsafe { atomic_sub(self.v.get(), val, order) }
12361240
}
12371241

1238-
/// Bitwise and with the current value, returning the previous value.
1242+
/// Bitwise "and" with the current value.
1243+
///
1244+
/// Performs a bitwise "and" operation on the current value and the argument `val`, and
1245+
/// sets the new value to the result.
1246+
///
1247+
/// Returns the previous value.
12391248
///
12401249
/// # Examples
12411250
///
@@ -1251,7 +1260,12 @@ macro_rules! atomic_int {
12511260
unsafe { atomic_and(self.v.get(), val, order) }
12521261
}
12531262

1254-
/// Bitwise or with the current value, returning the previous value.
1263+
/// Bitwise "or" with the current value.
1264+
///
1265+
/// Performs a bitwise "or" operation on the current value and the argument `val`, and
1266+
/// sets the new value to the result.
1267+
///
1268+
/// Returns the previous value.
12551269
///
12561270
/// # Examples
12571271
///
@@ -1267,7 +1281,12 @@ macro_rules! atomic_int {
12671281
unsafe { atomic_or(self.v.get(), val, order) }
12681282
}
12691283

1270-
/// Bitwise xor with the current value, returning the previous value.
1284+
/// Bitwise "xor" with the current value.
1285+
///
1286+
/// Performs a bitwise "xor" operation on the current value and the argument `val`, and
1287+
/// sets the new value to the result.
1288+
///
1289+
/// Returns the previous value.
12711290
///
12721291
/// # Examples
12731292
///
@@ -1415,7 +1434,7 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
14151434
}
14161435
}
14171436

1418-
/// Returns the old value (like __sync_fetch_and_add).
1437+
/// Returns the previous value (like __sync_fetch_and_add).
14191438
#[inline]
14201439
unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
14211440
match order {
@@ -1428,7 +1447,7 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
14281447
}
14291448
}
14301449

1431-
/// Returns the old value (like __sync_fetch_and_sub).
1450+
/// Returns the previous value (like __sync_fetch_and_sub).
14321451
#[inline]
14331452
unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
14341453
match order {

0 commit comments

Comments
 (0)