mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #20068 - paavininanda:autocloseworker, r=jdm
added AutoCloseWorker for closing related workers when a page/another worker is closed. <!-- Please describe your changes on the following line: --> Followed steps as suggested in issue. Error is not yet resolved! --- <!-- 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 fix #17977 (https://github.com/servo/servo/issues/17977?). <!-- Either: --> - [x] These changes do not require tests because it will have manual test case. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20068) <!-- Reviewable:end -->
This commit is contained in:
commit
9c484452c0
5 changed files with 38 additions and 0 deletions
|
@ -47,6 +47,8 @@ use std::collections::HashMap;
|
|||
use std::collections::hash_map::Entry;
|
||||
use std::ffi::CString;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use task::TaskCanceller;
|
||||
use task_source::file_reading::FileReadingTaskSource;
|
||||
use task_source::networking::NetworkingTaskSource;
|
||||
|
@ -55,6 +57,17 @@ use time::{Timespec, get_time};
|
|||
use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle};
|
||||
use timers::{OneshotTimers, TimerCallback};
|
||||
|
||||
#[derive(JSTraceable)]
|
||||
pub struct AutoCloseWorker(
|
||||
Arc<AtomicBool>,
|
||||
);
|
||||
|
||||
impl Drop for AutoCloseWorker {
|
||||
fn drop(&mut self) {
|
||||
self.0.store(true, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GlobalScope {
|
||||
eventtarget: EventTarget,
|
||||
|
@ -110,6 +123,10 @@ pub struct GlobalScope {
|
|||
/// <https://html.spec.whatwg.org/multipage/#microtask-queue>
|
||||
#[ignore_malloc_size_of = "Rc<T> is hard"]
|
||||
microtask_queue: Rc<MicrotaskQueue>,
|
||||
|
||||
/// Vector storing closing references of all workers
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
list_auto_close_worker: DomRefCell<Vec<AutoCloseWorker>>,
|
||||
}
|
||||
|
||||
impl GlobalScope {
|
||||
|
@ -142,9 +159,14 @@ impl GlobalScope {
|
|||
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
|
||||
origin,
|
||||
microtask_queue,
|
||||
list_auto_close_worker: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn track_worker(&self, closing_worker: Arc<AtomicBool>) {
|
||||
self.list_auto_close_worker.borrow_mut().push(AutoCloseWorker(closing_worker));
|
||||
}
|
||||
|
||||
/// Returns the global scope of the realm that the given DOM object's reflector
|
||||
/// was created in.
|
||||
#[allow(unsafe_code)]
|
||||
|
|
|
@ -79,6 +79,7 @@ impl Worker {
|
|||
let (sender, receiver) = channel();
|
||||
let closing = Arc::new(AtomicBool::new(false));
|
||||
let worker = Worker::new(global, sender.clone(), closing.clone());
|
||||
global.track_worker(closing.clone());
|
||||
let worker_ref = Trusted::new(&*worker);
|
||||
|
||||
let worker_load_origin = WorkerScriptLoadOrigin {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue