Skip to content

Commit 1b13d60

Browse files
committed
review feedback
1 parent d0f6b82 commit 1b13d60

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

crates/wasmtime/src/runtime/component/concurrent.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,7 @@ impl StoreOpaque {
15421542
/// situations.
15431543
pub fn enter_host_call(&mut self) -> Result<()> {
15441544
if !self.concurrency_support() {
1545+
self.enter_call_not_concurrent();
15451546
return Ok(());
15461547
}
15471548
let state = self.concurrent_state_mut();
@@ -1560,6 +1561,7 @@ impl StoreOpaque {
15601561
/// and will be cleaned up separately.
15611562
pub fn exit_host_call(&mut self) -> Result<()> {
15621563
if !self.concurrency_support() {
1564+
self.exit_call_not_concurrent();
15631565
return Ok(());
15641566
}
15651567
let task = self.concurrent_state_mut().unwrap_current_host_thread();

tests/all/component_model/func.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![cfg(not(miri))]
22

33
use super::{ApiStyle, REALLOC_AND_FREE};
4-
use std::sync::Arc;
4+
use std::sync::{
5+
Arc,
6+
atomic::{AtomicBool, Ordering::SeqCst},
7+
};
58
use wasmtime::Result;
69
use wasmtime::component::*;
710
use wasmtime::{Config, Engine, Store, StoreContextMut, Trap};
@@ -3771,5 +3774,75 @@ async fn drop_call_async_future() -> Result<()> {
37713774
_ = result;
37723775
}
37733776
}
3777+
3778+
Ok(())
3779+
}
3780+
3781+
#[test]
3782+
fn host_call_with_concurrency_disabled() -> Result<()> {
3783+
let mut config = Config::default();
3784+
config.concurrency_support(false);
3785+
3786+
struct MyResource;
3787+
3788+
let engine = Engine::new(&config)?;
3789+
let mut store = Store::new(&engine, ());
3790+
let mut linker = Linker::<()>::new(&engine);
3791+
3792+
linker
3793+
.root()
3794+
.resource("r", ResourceType::host::<MyResource>(), |_, _| Ok(()))?;
3795+
3796+
let f_called = Arc::new(AtomicBool::new(false));
3797+
linker.root().func_wrap("f", {
3798+
let f_called = f_called.clone();
3799+
move |_ctx, _: (Resource<MyResource>,)| -> Result<()> {
3800+
f_called.store(true, SeqCst);
3801+
Ok(())
3802+
}
3803+
})?;
3804+
3805+
let component = Component::new(
3806+
&engine,
3807+
r#"
3808+
(component
3809+
(import "r" (type $r (sub resource)))
3810+
(import "f" (func $f (param "r" (borrow $r))))
3811+
3812+
(core func $f' (canon lower (func $f)))
3813+
(core func $drop (canon resource.drop $r))
3814+
3815+
(core module $m
3816+
(import "" "f" (func $f (param i32)))
3817+
(import "" "drop" (func $drop (param i32)))
3818+
(func (export "g") (param i32)
3819+
(call $f (local.get 0))
3820+
(call $drop (local.get 0))
3821+
)
3822+
)
3823+
3824+
(core instance $i (instantiate $m (with
3825+
"" (instance
3826+
(export "f" (func $f'))
3827+
(export "drop" (func $drop))
3828+
)
3829+
)))
3830+
3831+
(func (export "g") (param "r" (borrow $r))
3832+
(canon lift (core func $i "g"))
3833+
)
3834+
)
3835+
"#
3836+
.as_bytes(),
3837+
)?;
3838+
3839+
let instance = linker.instantiate(&mut store, &component)?;
3840+
let g = instance.get_typed_func::<(&Resource<MyResource>,), ()>(&mut store, "g")?;
3841+
3842+
let resource = Resource::new_own(100);
3843+
g.call(&mut store, (&resource,))?;
3844+
3845+
assert!(f_called.load(SeqCst));
3846+
37743847
Ok(())
37753848
}

0 commit comments

Comments
 (0)