@@ -1126,33 +1126,9 @@ impl<T> StoreInner<T> {
11261126 CallHookInner :: Sync ( hook) => hook ( ( & mut * self ) . as_context_mut ( ) , s) ,
11271127
11281128 #[ cfg( all( feature = "async" , feature = "call-hook" ) ) ]
1129- CallHookInner :: Async ( handler) => unsafe {
1130- #[ cfg( feature = "component-model-async" ) ]
1131- {
1132- let async_cx = crate :: component:: concurrent:: AsyncCx :: try_new ( & mut self . inner )
1133- . ok_or_else ( || anyhow ! ( "couldn't grab async_cx for call hook" ) ) ?;
1134-
1135- async_cx
1136- . block_on (
1137- handler
1138- . handle_call_event ( ( & mut * self ) . as_context_mut ( ) , s)
1139- . as_mut ( ) ,
1140- None ,
1141- ) ?
1142- . 0
1143- }
1144- #[ cfg( not( feature = "component-model-async" ) ) ]
1145- {
1146- self . inner
1147- . async_cx ( )
1148- . ok_or_else ( || anyhow ! ( "couldn't grab async_cx for call hook" ) ) ?
1149- . block_on (
1150- handler
1151- . handle_call_event ( ( & mut * self ) . as_context_mut ( ) , s)
1152- . as_mut ( ) ,
1153- ) ?
1154- }
1155- } ,
1129+ CallHookInner :: Async ( handler) => {
1130+ self . block_on ( |store| handler. handle_call_event ( StoreContextMut ( store) , s) ) ?
1131+ }
11561132
11571133 CallHookInner :: ForceTypeParameterToBeUsed { uninhabited, .. } => {
11581134 let _ = s;
@@ -2047,36 +2023,12 @@ unsafe impl<T> crate::runtime::vm::VMStore for StoreInner<T> {
20472023 limiter ( & mut self . data ) . memory_growing ( current, desired, maximum)
20482024 }
20492025 #[ cfg( feature = "async" ) ]
2050- Some ( ResourceLimiterInner :: Async ( ref mut limiter) ) => unsafe {
2051- #[ cfg( feature = "component-model-async" ) ]
2052- {
2053- _ = limiter;
2054- let async_cx =
2055- crate :: component:: concurrent:: AsyncCx :: new ( & mut ( & mut * self ) . inner ) ;
2056- let Some ( ResourceLimiterInner :: Async ( ref mut limiter) ) = self . limiter else {
2057- unreachable ! ( ) ;
2058- } ;
2059- async_cx
2060- . block_on (
2061- limiter ( & mut self . data )
2062- . memory_growing ( current, desired, maximum)
2063- . as_mut ( ) ,
2064- None ,
2065- ) ?
2066- . 0
2067- }
2068- #[ cfg( not( feature = "component-model-async" ) ) ]
2069- {
2070- self . inner
2071- . async_cx ( )
2072- . expect ( "ResourceLimiterAsync requires async Store" )
2073- . block_on (
2074- limiter ( & mut self . data )
2075- . memory_growing ( current, desired, maximum)
2076- . as_mut ( ) ,
2077- ) ?
2078- }
2079- } ,
2026+ Some ( ResourceLimiterInner :: Async ( _) ) => self . block_on ( |store| {
2027+ let Some ( ResourceLimiterInner :: Async ( limiter) ) = & mut store. limiter else {
2028+ unreachable ! ( ) ;
2029+ } ;
2030+ limiter ( & mut store. data ) . memory_growing ( current, desired, maximum)
2031+ } ) ?,
20802032 None => Ok ( true ) ,
20812033 }
20822034 }
@@ -2103,50 +2055,17 @@ unsafe impl<T> crate::runtime::vm::VMStore for StoreInner<T> {
21032055 desired : usize ,
21042056 maximum : Option < usize > ,
21052057 ) -> Result < bool , anyhow:: Error > {
2106- // Need to borrow async_cx before the mut borrow of the limiter.
2107- // self.async_cx() panicks when used with a non-async store, so
2108- // wrap this in an option.
2109- #[ cfg( all( feature = "async" , not( feature = "component-model-async" ) ) ) ]
2110- let async_cx = if self . async_support ( )
2111- && matches ! ( self . limiter, Some ( ResourceLimiterInner :: Async ( _) ) )
2112- {
2113- Some ( self . async_cx ( ) . unwrap ( ) )
2114- } else {
2115- None
2116- } ;
2117-
21182058 match self . limiter {
21192059 Some ( ResourceLimiterInner :: Sync ( ref mut limiter) ) => {
21202060 limiter ( & mut self . data ) . table_growing ( current, desired, maximum)
21212061 }
21222062 #[ cfg( feature = "async" ) ]
2123- Some ( ResourceLimiterInner :: Async ( ref mut limiter) ) => unsafe {
2124- #[ cfg( feature = "component-model-async" ) ]
2125- {
2126- _ = limiter;
2127- let async_cx =
2128- crate :: component:: concurrent:: AsyncCx :: new ( & mut ( & mut * self ) . inner ) ;
2129- let Some ( ResourceLimiterInner :: Async ( ref mut limiter) ) = self . limiter else {
2130- unreachable ! ( ) ;
2131- } ;
2132- async_cx
2133- . block_on (
2134- limiter ( & mut self . data )
2135- . table_growing ( current, desired, maximum)
2136- . as_mut ( ) ,
2137- None ,
2138- ) ?
2139- . 0
2140- }
2141- #[ cfg( not( feature = "component-model-async" ) ) ]
2142- {
2143- async_cx
2144- . expect ( "ResourceLimiterAsync requires async Store" )
2145- . block_on (
2146- limiter ( & mut self . data ) . table_growing ( current, desired, maximum) ,
2147- ) ?
2148- }
2149- } ,
2063+ Some ( ResourceLimiterInner :: Async ( _) ) => self . block_on ( |store| {
2064+ let Some ( ResourceLimiterInner :: Async ( limiter) ) = & mut store. limiter else {
2065+ unreachable ! ( ) ;
2066+ } ;
2067+ limiter ( & mut store. data ) . table_growing ( current, desired, maximum)
2068+ } ) ?,
21502069 None => Ok ( true ) ,
21512070 }
21522071 }
@@ -2213,11 +2132,7 @@ unsafe impl<T> crate::runtime::vm::VMStore for StoreInner<T> {
22132132 // to clean up this fiber. Do so by raising a trap which will
22142133 // abort all wasm and get caught on the other side to clean
22152134 // things up.
2216- unsafe {
2217- self . async_cx ( )
2218- . expect ( "attempted to pull async context during shutdown" )
2219- . block_on ( future) ?
2220- }
2135+ self . block_on ( |_| future) ?;
22212136 delta
22222137 }
22232138 } ;
0 commit comments