global module registry: switch from Mutex to RwLock
@acfoltzer identified this on a code walk through wasmtime with me, and it was already noted in a comment that we could change if motivated.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
use crate::{signatures::SignatureCollection, Module};
|
use crate::{signatures::SignatureCollection, Module};
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
use wasmtime_environ::{
|
use wasmtime_environ::{
|
||||||
entity::EntityRef,
|
entity::EntityRef,
|
||||||
@@ -15,7 +15,7 @@ use wasmtime_jit::CompiledModule;
|
|||||||
use wasmtime_runtime::{ModuleInfo, VMCallerCheckedAnyfunc, VMTrampoline};
|
use wasmtime_runtime::{ModuleInfo, VMCallerCheckedAnyfunc, VMTrampoline};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref GLOBAL_MODULES: Mutex<GlobalModuleRegistry> = Default::default();
|
static ref GLOBAL_MODULES: RwLock<GlobalModuleRegistry> = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn func_by_pc(module: &CompiledModule, pc: usize) -> Option<(DefinedFuncIndex, u32)> {
|
fn func_by_pc(module: &CompiledModule, pc: usize) -> Option<(DefinedFuncIndex, u32)> {
|
||||||
@@ -88,7 +88,7 @@ impl ModuleRegistry {
|
|||||||
);
|
);
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
|
|
||||||
GLOBAL_MODULES.lock().unwrap().register(start, end, module);
|
GLOBAL_MODULES.write().unwrap().register(start, end, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Looks up a trampoline from an anyfunc.
|
/// Looks up a trampoline from an anyfunc.
|
||||||
@@ -100,7 +100,7 @@ impl ModuleRegistry {
|
|||||||
|
|
||||||
impl Drop for ModuleRegistry {
|
impl Drop for ModuleRegistry {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let mut info = GLOBAL_MODULES.lock().unwrap();
|
let mut info = GLOBAL_MODULES.write().unwrap();
|
||||||
for end in self.0.keys() {
|
for end in self.0.keys() {
|
||||||
info.unregister(*end);
|
info.unregister(*end);
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ impl GlobalModuleRegistry {
|
|||||||
/// Returns whether the `pc`, according to globally registered information,
|
/// Returns whether the `pc`, according to globally registered information,
|
||||||
/// is a wasm trap or not.
|
/// is a wasm trap or not.
|
||||||
pub(crate) fn is_wasm_pc(pc: usize) -> bool {
|
pub(crate) fn is_wasm_pc(pc: usize) -> bool {
|
||||||
let modules = GLOBAL_MODULES.lock().unwrap();
|
let modules = GLOBAL_MODULES.read().unwrap();
|
||||||
|
|
||||||
match modules.module(pc) {
|
match modules.module(pc) {
|
||||||
Some(entry) => match func_by_pc(&entry.module, pc) {
|
Some(entry) => match func_by_pc(&entry.module, pc) {
|
||||||
@@ -259,11 +259,8 @@ impl GlobalModuleRegistry {
|
|||||||
|
|
||||||
// Work with the global instance of `GlobalModuleRegistry`. Note that only
|
// Work with the global instance of `GlobalModuleRegistry`. Note that only
|
||||||
// shared access is allowed, this isn't intended to mutate the contents.
|
// shared access is allowed, this isn't intended to mutate the contents.
|
||||||
//
|
|
||||||
// (right now we use a `Mutex` but if motivated we could one day use a
|
|
||||||
// `RwLock`)
|
|
||||||
pub(crate) fn with<R>(f: impl FnOnce(&GlobalModuleRegistry) -> R) -> R {
|
pub(crate) fn with<R>(f: impl FnOnce(&GlobalModuleRegistry) -> R) -> R {
|
||||||
f(&GLOBAL_MODULES.lock().unwrap())
|
f(&GLOBAL_MODULES.read().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches frame information about a program counter in a backtrace.
|
/// Fetches frame information about a program counter in a backtrace.
|
||||||
|
|||||||
Reference in New Issue
Block a user