summaryrefslogtreecommitdiff
path: root/examples/list.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2025-02-28 16:09:11 -0500
committerBotahamec <botahamec@outlook.com>2025-02-28 16:09:11 -0500
commit4ba03be97e6cc7e790bbc9bfc18caaa228c8a262 (patch)
treea257184577a93ddf240aba698755c2886188788b /examples/list.rs
parent4a5ec04a29cba07c5960792528bd66b0f99ee3ee (diff)
Scoped lock API
Diffstat (limited to 'examples/list.rs')
-rw-r--r--examples/list.rs17
1 files changed, 9 insertions, 8 deletions
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<usize>; 6] = [
static SEED: Mutex<u32> = 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];