From 75f4ed0d23b06634f7831663f51ac6e4cb354201 Mon Sep 17 00:00:00 2001 From: Cherry <13651622+MolotovCherry@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:52:28 -0800 Subject: [PATCH] Combine the load+store into a swap --- crates/yabg3nml/src/server.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/yabg3nml/src/server.rs b/crates/yabg3nml/src/server.rs index e085af6..185cd3a 100644 --- a/crates/yabg3nml/src/server.rs +++ b/crates/yabg3nml/src/server.rs @@ -67,15 +67,11 @@ pub fn server() -> io::Result { return ControlFlow::Break(()); } - // load current auth code - let passcode = AUTH.load(Ordering::Relaxed); + // load current auth code; also change auth code to always keep it randomized + let passcode = AUTH.swap(rand::random::(), Ordering::Relaxed); trace!(code, passcode, "verifying auth code"); - // change auth code to always keep it randomized - let auth_code = rand::random::(); - AUTH.store(auth_code, Ordering::Relaxed); - if passcode == code { ControlFlow::Continue(()) } else {