Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note about overflow for fetch_add/fetch_sub #40927

Merged
merged 2 commits into from Apr 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl AtomicBool {
}
}

/// 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.
Expand Down Expand Up @@ -703,7 +703,7 @@ impl<T> AtomicPtr<T> {
}
}

/// 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.
Expand Down Expand Up @@ -1015,7 +1015,7 @@ macro_rules! atomic_int {
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.
Expand Down Expand Up @@ -1169,7 +1169,9 @@ macro_rules! atomic_int {
}
}

/// 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
///
Expand All @@ -1186,7 +1188,9 @@ macro_rules! atomic_int {
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
///
Expand All @@ -1203,7 +1207,12 @@ macro_rules! atomic_int {
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
///
Expand All @@ -1219,7 +1228,12 @@ macro_rules! atomic_int {
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
///
Expand All @@ -1235,7 +1249,12 @@ macro_rules! atomic_int {
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
///
Expand Down Expand Up @@ -1383,7 +1402,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 {
Expand All @@ -1396,7 +1415,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 {
Expand Down