Skip to content

Commit 00468e3

Browse files
committed
Rewrite docs for fetch_update for clarity
1 parent 68ac5ab commit 00468e3

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

library/core/src/sync/atomic.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,23 +3326,23 @@ macro_rules! atomic_int {
33263326
unsafe { atomic_xor(self.v.get(), val, order) }
33273327
}
33283328

3329-
/// Fetches the value, and applies a function to it that returns an optional
3330-
/// new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else
3331-
/// `Err(previous_value)`.
3329+
/// Loads the current value, applies a closure to it, and optionally tries to store a new value.
33323330
///
3333-
/// Note: This may call the function multiple times if the value has been changed from other threads in
3334-
/// the meantime, as long as the function returns `Some(_)`, but the function will have been applied
3335-
/// only once to the stored value.
3331+
/// If the closure ever returns None, this method will immediately return `Err(current value)`.
3332+
/// If the closure returns Some(new value), then this method calls
3333+
#[doc = concat!("[`", stringify!($atomic_type), "::compare_exchange_weak`]")]
3334+
/// to try to store the new value.
33363335
///
3337-
/// `fetch_update` takes two [`Ordering`] arguments to describe the memory ordering of this operation.
3338-
/// The first describes the required ordering for when the operation finally succeeds while the second
3339-
/// describes the required ordering for loads. These correspond to the success and failure orderings of
3340-
#[doc = concat!("[`", stringify!($atomic_type), "::compare_exchange`]")]
3341-
/// respectively.
3336+
/// If storing a new value fails (due to another thread changing the current value),
3337+
/// then the given closure will be called again on the new current value
3338+
/// (returned by `compare_exchange_weak`), until either the closure returns None,
3339+
/// or `compare_exchange_weak` succeeds in storing a new value.
33423340
///
3343-
/// Using [`Acquire`] as success ordering makes the store part
3344-
/// of this operation [`Relaxed`], and using [`Release`] makes the final successful load
3345-
/// [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`], [`Acquire`] or [`Relaxed`].
3341+
/// Returns `Ok(previous value)` if it ever succeeds in storing a new value,
3342+
/// otherwise returns `Err(current value)`.
3343+
///
3344+
/// Takes a `set_order` and a `fetch_order` [`Ordering`] to pass on to `compare_exchange_weak`,
3345+
/// and also uses the `fetch_order` for the initial load.
33463346
///
33473347
/// **Note**: This method is only available on platforms that support atomic operations on
33483348
#[doc = concat!("[`", $s_int_type, "`].")]

0 commit comments

Comments
 (0)