mirror of
https://github.com/servo/servo.git
synced 2025-07-29 18:20:24 +01:00
Auto merge of #24757 - Akash-Pateria:async-wasm-compilation-subsequent, r=jdm
Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
This commit is contained in:
commit
dc22a78cc2
68 changed files with 162 additions and 427 deletions
|
@ -32,6 +32,7 @@ use crate::script_runtime::{
|
|||
new_child_runtime, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan, ScriptPort,
|
||||
};
|
||||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::networking::NetworkingTaskSource;
|
||||
use crate::task_source::TaskSourceName;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use devtools_traits::DevtoolScriptControlMsg;
|
||||
|
@ -344,7 +345,16 @@ impl DedicatedWorkerGlobalScope {
|
|||
.referrer_policy(referrer_policy)
|
||||
.origin(origin);
|
||||
|
||||
let runtime = unsafe { new_child_runtime(parent) };
|
||||
let runtime = unsafe {
|
||||
if let Some(pipeline_id) = pipeline_id {
|
||||
new_child_runtime(
|
||||
parent,
|
||||
Some(NetworkingTaskSource(parent_sender.clone(), pipeline_id)),
|
||||
)
|
||||
} else {
|
||||
new_child_runtime(parent, None)
|
||||
}
|
||||
};
|
||||
|
||||
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
|
||||
ROUTER.route_ipc_receiver_to_crossbeam_sender(
|
||||
|
|
|
@ -315,7 +315,7 @@ impl ServiceWorkerGlobalScope {
|
|||
},
|
||||
};
|
||||
|
||||
let runtime = new_rt_and_cx();
|
||||
let runtime = new_rt_and_cx(None);
|
||||
|
||||
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
|
||||
ROUTER
|
||||
|
|
|
@ -477,7 +477,7 @@ impl WorkletThread {
|
|||
global_init: init.global_init,
|
||||
global_scopes: HashMap::new(),
|
||||
control_buffer: None,
|
||||
runtime: new_rt_and_cx(),
|
||||
runtime: new_rt_and_cx(None),
|
||||
should_gc: false,
|
||||
gc_threshold: MIN_GC_THRESHOLD,
|
||||
});
|
||||
|
|
|
@ -32,17 +32,20 @@ use crate::dom::response::Response;
|
|||
use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue};
|
||||
use crate::script_thread::trace_thread;
|
||||
use crate::task::TaskBox;
|
||||
use crate::task_source::networking::NetworkingTaskSource;
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, SetBuildId};
|
||||
use js::glue::{RUST_js_GetErrorMessage, StreamConsumerConsumeChunk, StreamConsumerStreamEnd};
|
||||
use js::glue::{StreamConsumerNoteResponseURLs, StreamConsumerStreamError};
|
||||
use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, DispatchableRun};
|
||||
use js::glue::{JobQueueTraps, RUST_js_GetErrorMessage, SetBuildId, StreamConsumerConsumeChunk};
|
||||
use js::glue::{
|
||||
StreamConsumerNoteResponseURLs, StreamConsumerStreamEnd, StreamConsumerStreamError,
|
||||
};
|
||||
use js::jsapi::ContextOptionsRef;
|
||||
use js::jsapi::Dispatchable;
|
||||
use js::jsapi::InitConsumeStreamCallback;
|
||||
use js::jsapi::InitDispatchToEventLoop;
|
||||
use js::jsapi::MimeType;
|
||||
use js::jsapi::StreamConsumer as JSStreamConsumer;
|
||||
use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress};
|
||||
use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown};
|
||||
use js::jsapi::{HandleObject, Heap, JobQueue};
|
||||
use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback};
|
||||
use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback};
|
||||
|
@ -397,17 +400,23 @@ lazy_static! {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub unsafe fn new_child_runtime(parent: ParentRuntime) -> Runtime {
|
||||
new_rt_and_cx_with_parent(Some(parent))
|
||||
pub unsafe fn new_child_runtime(
|
||||
parent: ParentRuntime,
|
||||
networking_task_source: Option<NetworkingTaskSource>,
|
||||
) -> Runtime {
|
||||
new_rt_and_cx_with_parent(Some(parent), networking_task_source)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new_rt_and_cx() -> Runtime {
|
||||
unsafe { new_rt_and_cx_with_parent(None) }
|
||||
pub fn new_rt_and_cx(networking_task_source: Option<NetworkingTaskSource>) -> Runtime {
|
||||
unsafe { new_rt_and_cx_with_parent(None, networking_task_source) }
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
|
||||
unsafe fn new_rt_and_cx_with_parent(
|
||||
parent: Option<ParentRuntime>,
|
||||
networking_task_source: Option<NetworkingTaskSource>,
|
||||
) -> Runtime {
|
||||
LiveDOMReferences::initialize();
|
||||
let runtime = if let Some(parent) = parent {
|
||||
RustRuntime::create_with_parent(parent)
|
||||
|
@ -436,12 +445,26 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
|
|||
DisableIncrementalGC(cx);
|
||||
|
||||
unsafe extern "C" fn dispatch_to_event_loop(
|
||||
_closure: *mut c_void,
|
||||
_dispatchable: *mut Dispatchable,
|
||||
closure: *mut c_void,
|
||||
dispatchable: *mut JSRunnable,
|
||||
) -> bool {
|
||||
false
|
||||
let networking_task_src: &NetworkingTaskSource = &*(closure as *mut NetworkingTaskSource);
|
||||
let runnable = Runnable(dispatchable);
|
||||
let task = task!(dispatch_to_event_loop_message: move || {
|
||||
runnable.run(RustRuntime::get(), Dispatchable_MaybeShuttingDown::NotShuttingDown);
|
||||
});
|
||||
|
||||
networking_task_src.queue_unconditionally(task).is_ok()
|
||||
}
|
||||
|
||||
if let Some(source) = networking_task_source {
|
||||
let networking_task_src = Box::new(source);
|
||||
InitDispatchToEventLoop(
|
||||
cx,
|
||||
Some(dispatch_to_event_loop),
|
||||
Box::into_raw(networking_task_src) as *mut c_void,
|
||||
);
|
||||
}
|
||||
InitDispatchToEventLoop(cx, Some(dispatch_to_event_loop), ptr::null_mut());
|
||||
|
||||
InitConsumeStreamCallback(cx, Some(consume_stream), Some(report_stream_error));
|
||||
|
||||
|
@ -939,3 +962,19 @@ unsafe extern "C" fn report_stream_error(_cx: *mut RawJSContext, error_code: usi
|
|||
RUST_js_GetErrorMessage(ptr::null_mut(), error_code as u32)
|
||||
);
|
||||
}
|
||||
|
||||
pub struct Runnable(*mut JSRunnable);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl Sync for Runnable {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl Send for Runnable {}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl Runnable {
|
||||
fn run(&self, cx: *mut RawJSContext, maybe_shutting_down: Dispatchable_MaybeShuttingDown) {
|
||||
unsafe {
|
||||
DispatchableRun(cx, self.0, maybe_shutting_down);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1244,7 +1244,12 @@ impl ScriptThread {
|
|||
replace_surrogates: bool,
|
||||
user_agent: Cow<'static, str>,
|
||||
) -> ScriptThread {
|
||||
let runtime = new_rt_and_cx();
|
||||
let boxed_script_sender = Box::new(MainThreadScriptChan(chan.clone()));
|
||||
|
||||
let runtime = new_rt_and_cx(Some(NetworkingTaskSource(
|
||||
boxed_script_sender.clone(),
|
||||
state.id,
|
||||
)));
|
||||
let cx = runtime.cx();
|
||||
|
||||
unsafe {
|
||||
|
@ -1262,8 +1267,6 @@ impl ScriptThread {
|
|||
// Ask the router to proxy IPC messages from the control port to us.
|
||||
let control_port = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(state.control_port);
|
||||
|
||||
let boxed_script_sender = Box::new(MainThreadScriptChan(chan.clone()));
|
||||
|
||||
let (image_cache_channel, image_cache_port) = unbounded();
|
||||
|
||||
let task_queue = TaskQueue::new(port, chan.clone());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue