From 5b9620df7ac655449abd2cce5292bd4669b1f211 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 11 Nov 2022 05:44:53 -0800 Subject: feat(ops): implement fast lazy async ops (#16579) Implements fast scheduling of deferred op futures. ```rs #[op(fast)] async fn op_read( state: Rc>, rid: ResourceId, buf: &mut [u8], ) -> Result { // ... } ``` The future is scheduled via a fast API call and polled by the event loop after being woken up by its waker. --- core/lib.rs | 2 ++ core/runtime.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'core') diff --git a/core/lib.rs b/core/lib.rs index adda98046..607d90f0b 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -121,7 +121,9 @@ pub mod _ops { pub use super::error_codes::get_error_code; pub use super::ops::to_op_result; pub use super::ops::OpCtx; + pub use super::ops::OpResult; pub use super::runtime::queue_async_op; + pub use super::runtime::queue_fast_async_op; pub use super::runtime::V8_WRAPPER_OBJECT_INDEX; pub use super::runtime::V8_WRAPPER_TYPE_INDEX; } diff --git a/core/runtime.rs b/core/runtime.rs index 21e6e7570..376e0beb4 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2202,6 +2202,22 @@ impl JsRealm { // TODO(andreubotella): `mod_evaluate`, `load_main_module`, `load_side_module` } +#[inline] +pub fn queue_fast_async_op( + ctx: &OpCtx, + op: impl Future + 'static, +) { + let runtime_state = match ctx.runtime_state.upgrade() { + Some(rc_state) => rc_state, + // atleast 1 Rc is held by the JsRuntime. + None => unreachable!(), + }; + + let mut state = runtime_state.borrow_mut(); + state.pending_ops.push(OpCall::lazy(op)); + state.have_unpolled_ops = true; +} + #[inline] pub fn queue_async_op( ctx: &OpCtx, -- cgit v1.2.3