Skip to content

Commit

Permalink
fix concurrency bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Oct 16, 2023
1 parent a1affcc commit d00d882
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions test/src/wasms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,19 @@ impl TestWasm {
cranelift
};

assert!(SERIALIZED_MODULE_CACHE
.set(parking_lot::RwLock::new(
SerializedModuleCache::default_with_cranelift(if metered {
cranelift_fn
} else {
cranelift_fn_unmetered
})
))
.is_ok());
SERIALIZED_MODULE_CACHE
.get()
.unwrap()
.write()
.get(self.key(metered), self.bytes())
.unwrap()
// This will error if the cache is already initialized
// which could happen if two tests are running in parallel.
// It doesn't matter which one wins, so we just ignore the error.
let _did_init_ok = SERIALIZED_MODULE_CACHE.set(parking_lot::RwLock::new(
SerializedModuleCache::default_with_cranelift(if metered {
cranelift_fn
} else {
cranelift_fn_unmetered
}),
));

// Just recurse now that the cache is initialized.
self.module(metered)
}
}
}
Expand Down

0 comments on commit d00d882

Please sign in to comment.