From 4ba03be97e6cc7e790bbc9bfc18caaa228c8a262 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 28 Feb 2025 16:09:11 -0500 Subject: Scoped lock API --- examples/list.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/list.rs b/examples/list.rs index a649eeb..fb3a405 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -16,13 +16,14 @@ static DATA: [Mutex; 6] = [ static SEED: Mutex = Mutex::new(42); fn random(key: &mut ThreadKey) -> usize { - let mut seed = SEED.lock(key); - let x = *seed; - let x = x ^ (x << 13); - let x = x ^ (x >> 17); - let x = x ^ (x << 5); - *seed = x; - x as usize + SEED.scoped_lock(key, |seed| { + let x = *seed; + let x = x ^ (x << 13); + let x = x ^ (x >> 17); + let x = x ^ (x << 5); + *seed = x; + x as usize + }) } fn main() { @@ -40,7 +41,7 @@ fn main() { let Some(lock) = RefLockCollection::try_new(&data) else { continue; }; - let mut guard = lock.lock(&mut key); + let mut guard = lock.lock(key); *guard[0] += *guard[1]; *guard[1] += *guard[2]; *guard[2] += *guard[0]; -- cgit v1.2.3