Memory::new_async, grow_async now work!

This commit is contained in:
Pat Hickey
2021-10-20 18:34:26 -07:00
parent adf7521e30
commit 2225722373
3 changed files with 53 additions and 17 deletions

View File

@@ -503,19 +503,19 @@ impl<'a> Instantiator<'a> {
// NB: this is the same code as `run`. It's intentionally
// small but should be kept in sync (modulo the async bits).
loop {
let step = self.step(store.0)?;
if let Some((instance, start, toplevel)) = step {
if let Some(start) = start {
store
.on_fiber(|store| Instantiator::start_raw(store, instance, start))
.await??;
store
.on_fiber(|store| loop {
let step = self.step(store.0)?;
if let Some((instance, start, toplevel)) = step {
if let Some(start) = start {
Instantiator::start_raw(store, instance, start)?
}
if toplevel {
break Ok(instance);
}
}
if toplevel {
break Ok(instance);
}
}
}
})
.await?
}
/// Processes the next initializer for the next instance being created

View File

@@ -223,6 +223,24 @@ impl Memory {
Memory::_new(store.as_context_mut().0, ty)
}
/// Async variant of [`Memory::new`]. You must use this variant with Stores which have a
/// [`ResourceLimiterAsync`].
#[cfg(feature = "async")]
pub async fn new_async<T>(
mut store: impl AsContextMut<Data = T>,
ty: MemoryType,
) -> Result<Memory>
where
T: Send,
{
let mut store = store.as_context_mut();
assert!(
store.0.async_support(),
"cannot use `new_async` without enabling async support on the config"
);
store.on_fiber(|store| Memory::_new(store.0, ty)).await?
}
fn _new(store: &mut StoreOpaque, ty: MemoryType) -> Result<Memory> {
unsafe {
let export = generate_memory_export(store, &ty)?;
@@ -472,6 +490,23 @@ impl Memory {
}
}
/// Async variant of [`Memory::grow`]. Required when using a [`ResourceLimiterAsync`].
#[cfg(feature = "async")]
pub async fn grow_async<T>(
&self,
mut store: impl AsContextMut<Data = T>,
delta: u64,
) -> Result<u64>
where
T: Send,
{
let mut store = store.as_context_mut();
assert!(
store.0.async_support(),
"cannot use `grow_async` without enabling async support on the config"
);
store.on_fiber(|store| self.grow(store, delta)).await?
}
fn wasmtime_memory(&self, store: &mut StoreOpaque) -> *mut wasmtime_runtime::Memory {
unsafe {
let export = &store[self.0];