Skip to content

Commit

Permalink
Add discretionary locking to from_module
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Nov 26, 2021
1 parent f32aa82 commit cffc6fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct Cache<A: BackendApi, S: Storage, Q: Querier> {
type_api: PhantomData<A>,
type_storage: PhantomData<S>,
type_querier: PhantomData<Q>,
m: Mutex<()>,
}

#[derive(PartialEq, Debug)]
Expand Down Expand Up @@ -131,6 +132,7 @@ where
type_storage: PhantomData::<S>,
type_api: PhantomData::<A>,
type_querier: PhantomData::<Q>,
m: Mutex::new(()),
})
}

Expand Down Expand Up @@ -261,6 +263,7 @@ where
options.gas_limit,
options.print_debug,
None,
Some(&self.m),
)?;
Ok(instance)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::ptr::NonNull;
use std::sync::Mutex;

use wasmer::{Exports, Function, ImportObject, Instance as WasmerInstance, Module, Val};

Expand Down Expand Up @@ -69,6 +70,7 @@ where
options.gas_limit,
options.print_debug,
None,
None,
)
}

Expand All @@ -78,7 +80,9 @@ where
gas_limit: u64,
print_debug: bool,
extra_imports: Option<HashMap<&str, Exports>>,
m: Option<&Mutex<()>>,
) -> VmResult<Self> {
let _lock = m.map(|m| m.lock().unwrap());
let store = module.store();

let env = Environment::new(backend.api, gas_limit, print_debug);
Expand Down Expand Up @@ -363,7 +367,7 @@ where
S: Storage + 'static, // 'static is needed here to allow using this in an Environment that is cloned into closures
Q: Querier + 'static,
{
Instance::from_module(module, backend, gas_limit, print_debug, extra_imports)
Instance::from_module(module, backend, gas_limit, print_debug, extra_imports, None)
}

#[cfg(test)]
Expand Down Expand Up @@ -462,6 +466,7 @@ mod tests {
instance_options.gas_limit,
false,
Some(extra_imports),
None,
)
.unwrap();

Expand Down

0 comments on commit cffc6fc

Please sign in to comment.