Repository: tokio-rs/tokio
File: tokio/src/runtime/task/state.rs (Rust)

Code before:
                    action = TransitionToNotifiedByVal::DoNothing;
                }
            } else {
                // We create a new notified that we can submit. The caller
                // retains ownership of the ref-count they passed in.
                snapshot.set_notified();
                snapshot.ref_inc();
                action = TransitionToNotifiedByVal::Submit;
            }

            (action, Some(snapshot))
        })
    }

    /// Transitions the state to `NOTIFIED`.
    pub(super) fn transition_to_notified_by_ref(&self) -> TransitionToNotifiedByRef {
        self.fetch_update_action(|mut snapshot| {
            if snapshot.is_complete() || snapshot.is_notified() {
                // It's possible to get old value with load(), on some hardware with weak
                // memory order. Although we have nothing to do in this branch,
                // use additional atomic CAS with the same value to ensure happen-before relationship.
                (TransitionToNotifiedByRef::DoNothing, Some(snapshot))
            } else if snapshot.is_running() {
                // If the task is running, we mark it as notified, but we should
                // not submit as the thread currently running the future is
                // responsible for that.
                snapshot.set_notified();
                (TransitionToNotifiedByRef::DoNothing, Some(snapshot))
            } else {
                // The task is idle and not notified. We should submit a
                // notification.
                snapshot.set_notified();
                snapshot.ref_inc();
                (TransitionToNotifiedByRef::Submit, Some(snapshot))
            }
        })
    }

    /// Transitions the state to `NOTIFIED`, unconditionally increasing the ref
    /// count.
    ///
    /// Returns `true` if the notified bit was transitioned from `0` to `1`;
    /// otherwise `false.`
    #[cfg(all(
        tokio_unstable,
        tokio_taskdump,
        feature = "rt",
        target_os = "linux",
        any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
    ))]
    pub(super) fn transition_to_notified_for_tracing(&self) -> bool {

Review comment (suggestion):
We only need `Some(snapshot)` in the `is_notified()` case because `is_complete()` is a permanent condition. If the old value is complete, then the latest value is also complete.

Code after:
                    action = TransitionToNotifiedByVal::DoNothing;
                }
            } else {
                // We create a new notified that we can submit. The caller
                // retains ownership of the ref-count they passed in.
                snapshot.set_notified();
                snapshot.ref_inc();
                action = TransitionToNotifiedByVal::Submit;
            }

            (action, Some(snapshot))
        })
    }

    /// Transitions the state to `NOTIFIED`.
    pub(super) fn transition_to_notified_by_ref(&self) -> TransitionToNotifiedByRef {
        self.fetch_update_action(|mut snapshot| {
            if snapshot.is_complete() {
                // The complete state is final
                (TransitionToNotifiedByRef::DoNothing, None)
            } else if snapshot.is_notified() {
                // Even hough we have nothing to do in this branch,
                // wake_by_ref() should synchronize-with the task starting execution,
                // therefore we must use an Release store (with the same value),
                // to pair with the Acquire in transition_to_running.
                (TransitionToNotifiedByRef::DoNothing, Some(snapshot))
            } else if snapshot.is_running() {
                // If the task is running, we mark it as notified, but we should
                // not submit as the thread currently running the future is
                // responsible for that.
                snapshot.set_notified();
                (TransitionToNotifiedByRef::DoNothing, Some(snapshot))
            } else {
                // The task is idle and not notified. We should submit a
                // notification.
                snapshot.set_notified();
                snapshot.ref_inc();
                (TransitionToNotifiedByRef::Submit, Some(snapshot))
            }
        })
    }

    /// Transitions the state to `NOTIFIED`, unconditionally increasing the ref
    /// count.
    ///
    /// Returns `true` if the notified bit was transitioned from `0` to `1`;
    /// otherwise `false.`
    #[cfg(all(
        tokio_unstable,
        tokio_taskdump,
        feature = "rt",