提交 fc5ff66b 编写于 作者: A Ariel Ben-Yehuda 提交者: GitHub

Rollup 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
......@@ -321,7 +321,7 @@ pub fn store(&self, val: bool, order: Ordering) {
}
}
/// Stores a value into the bool, returning the old value.
/// Stores a value into the bool, returning the previous value.
///
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
/// of this operation.
......@@ -732,7 +732,7 @@ pub fn store(&self, ptr: *mut T, order: Ordering) {
}
}
/// Stores a value into the pointer, returning the old value.
/// Stores a value into the pointer, returning the previous value.
///
/// `swap` takes an [`Ordering`] argument which describes the memory ordering
/// of this operation.
......@@ -1047,7 +1047,7 @@ pub fn store(&self, val: $int_type, order: Ordering) {
unsafe { atomic_store(self.v.get(), val, order); }
}
/// Stores a value into the atomic integer, returning the old value.
/// Stores a value into the atomic integer, returning the previous value.
///
/// `swap` takes an [`Ordering`] argument which describes the memory ordering of this
/// operation.
......@@ -1201,7 +1201,9 @@ pub fn compare_exchange_weak(&self,
}
}
/// Add to the current value, returning the previous value.
/// Adds to the current value, returning the previous value.
///
/// This operation wraps around on overflow.
///
/// # Examples
///
......@@ -1218,7 +1220,9 @@ pub fn fetch_add(&self, val: $int_type, order: Ordering) -> $int_type {
unsafe { atomic_add(self.v.get(), val, order) }
}
/// Subtract from the current value, returning the previous value.
/// Subtracts from the current value, returning the previous value.
///
/// This operation wraps around on overflow.
///
/// # Examples
///
......@@ -1235,7 +1239,12 @@ pub fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type {
unsafe { atomic_sub(self.v.get(), val, order) }
}
/// Bitwise and with the current value, returning the previous value.
/// Bitwise "and" with the current value.
///
/// Performs a bitwise "and" operation on the current value and the argument `val`, and
/// sets the new value to the result.
///
/// Returns the previous value.
///
/// # Examples
///
......@@ -1251,7 +1260,12 @@ pub fn fetch_and(&self, val: $int_type, order: Ordering) -> $int_type {
unsafe { atomic_and(self.v.get(), val, order) }
}
/// Bitwise or with the current value, returning the previous value.
/// Bitwise "or" with the current value.
///
/// Performs a bitwise "or" operation on the current value and the argument `val`, and
/// sets the new value to the result.
///
/// Returns the previous value.
///
/// # Examples
///
......@@ -1267,7 +1281,12 @@ pub fn fetch_or(&self, val: $int_type, order: Ordering) -> $int_type {
unsafe { atomic_or(self.v.get(), val, order) }
}
/// Bitwise xor with the current value, returning the previous value.
/// Bitwise "xor" with the current value.
///
/// Performs a bitwise "xor" operation on the current value and the argument `val`, and
/// sets the new value to the result.
///
/// Returns the previous value.
///
/// # Examples
///
......@@ -1415,7 +1434,7 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
}
}
/// Returns the old value (like __sync_fetch_and_add).
/// Returns the previous value (like __sync_fetch_and_add).
#[inline]
unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
......@@ -1428,7 +1447,7 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
}
}
/// Returns the old value (like __sync_fetch_and_sub).
/// Returns the previous value (like __sync_fetch_and_sub).
#[inline]
unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册