mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
script: Eliminate code duplication in the task queue (#34798)
Instead of creating a type for each `TaskSource` variety have each `TaskSource` hold the same kind of sender (this was inconsistent before, but each sender was effectively the same trait object), a pipeline, and a `TaskSourceName`. This elminates the need to reimplement the same queuing code for every task source. In addition, have workers hold their own `TaskManager`. This allows just exposing the manager on the `GlobalScope`. Currently the `TaskCanceller` is different, but this will also be eliminated in a followup change. This is a the first step toward having a shared set of `Sender`s on `GlobalScope`. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
deb819f233
commit
77cfca65c4
67 changed files with 432 additions and 1200 deletions
|
@ -73,7 +73,7 @@ use crate::dom::xmlhttprequestupload::XMLHttpRequestUpload;
|
|||
use crate::fetch::FetchCanceller;
|
||||
use crate::network_listener::{self, PreInvoke, ResourceTimingListener};
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
use crate::task_source::networking::NetworkingTaskSource;
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
use crate::timers::{OneshotTimerCallback, OneshotTimerHandle};
|
||||
|
||||
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
|
@ -294,7 +294,7 @@ impl XMLHttpRequest {
|
|||
|
||||
fn initiate_async_xhr(
|
||||
context: Arc<Mutex<XHRContext>>,
|
||||
task_source: NetworkingTaskSource,
|
||||
task_source: TaskSource,
|
||||
global: &GlobalScope,
|
||||
init: RequestBuilder,
|
||||
cancellation_chan: ipc::IpcReceiver<()>,
|
||||
|
@ -1560,10 +1560,17 @@ impl XMLHttpRequest {
|
|||
}));
|
||||
|
||||
let (task_source, script_port) = if self.sync.get() {
|
||||
let (tx, rx) = global.new_script_pair();
|
||||
(NetworkingTaskSource(tx, global.pipeline_id()), Some(rx))
|
||||
let (sender, receiver) = global.new_script_pair();
|
||||
(
|
||||
TaskSource {
|
||||
sender,
|
||||
pipeline_id: global.pipeline_id(),
|
||||
name: TaskSourceName::Networking,
|
||||
},
|
||||
Some(receiver),
|
||||
)
|
||||
} else {
|
||||
(global.networking_task_source(), None)
|
||||
(global.task_manager().networking_task_source(), None)
|
||||
};
|
||||
|
||||
let cancel_receiver = self.canceller.borrow_mut().initialize();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue