mirror of
https://github.com/servo/servo.git
synced 2025-07-30 10:40:27 +01:00
Auto merge of #22474 - csmoe:unregister, r=gterzian
Unregister components while exiting r=@gterzian <!-- Please describe your changes on the following line: --> --- <!-- 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 #22468 (GitHub issue number if applicable) <!-- 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/22474) <!-- Reviewable:end -->
This commit is contained in:
commit
a067620789
5 changed files with 44 additions and 0 deletions
|
@ -72,6 +72,8 @@ impl BackgroundHangMonitorClone for HangMonitorRegister {
|
||||||
pub enum MonitoredComponentMsg {
|
pub enum MonitoredComponentMsg {
|
||||||
/// Register component for monitoring,
|
/// Register component for monitoring,
|
||||||
Register(Box<Sampler>, Duration, Duration),
|
Register(Box<Sampler>, Duration, Duration),
|
||||||
|
/// Unregister component for monitoring.
|
||||||
|
Unregister,
|
||||||
/// Notify start of new activity for a given component,
|
/// Notify start of new activity for a given component,
|
||||||
NotifyActivity(HangAnnotation),
|
NotifyActivity(HangAnnotation),
|
||||||
/// Notify start of waiting for a new task to come-in for processing.
|
/// Notify start of waiting for a new task to come-in for processing.
|
||||||
|
@ -119,6 +121,10 @@ impl BackgroundHangMonitor for BackgroundHangMonitorChan {
|
||||||
let msg = MonitoredComponentMsg::NotifyWait;
|
let msg = MonitoredComponentMsg::NotifyWait;
|
||||||
self.send(msg);
|
self.send(msg);
|
||||||
}
|
}
|
||||||
|
fn unregister(&self) {
|
||||||
|
let msg = MonitoredComponentMsg::Unregister;
|
||||||
|
self.send(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MonitoredComponent {
|
struct MonitoredComponent {
|
||||||
|
@ -200,6 +206,12 @@ impl BackgroundHangMonitorWorker {
|
||||||
"This component was already registered for monitoring."
|
"This component was already registered for monitoring."
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
(component_id, MonitoredComponentMsg::Unregister) => {
|
||||||
|
let _ = self
|
||||||
|
.monitored_components
|
||||||
|
.remove_entry(&component_id)
|
||||||
|
.expect("Received Unregister for an unknown component");
|
||||||
|
},
|
||||||
(component_id, MonitoredComponentMsg::NotifyActivity(annotation)) => {
|
(component_id, MonitoredComponentMsg::NotifyActivity(annotation)) => {
|
||||||
let component = self
|
let component = self
|
||||||
.monitored_components
|
.monitored_components
|
||||||
|
|
|
@ -105,3 +105,30 @@ fn test_hang_monitoring() {
|
||||||
// Still no new alerts because the hang monitor has shut-down already.
|
// Still no new alerts because the hang monitor has shut-down already.
|
||||||
assert!(background_hang_monitor_receiver.try_recv().is_err());
|
assert!(background_hang_monitor_receiver.try_recv().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hang_monitoring_unregister() {
|
||||||
|
let (background_hang_monitor_ipc_sender, background_hang_monitor_receiver) =
|
||||||
|
ipc::channel().expect("ipc channel failure");
|
||||||
|
|
||||||
|
let background_hang_monitor_register =
|
||||||
|
HangMonitorRegister::init(background_hang_monitor_ipc_sender.clone());
|
||||||
|
let background_hang_monitor = background_hang_monitor_register.register_component(
|
||||||
|
MonitoredComponentId(TEST_PIPELINE_ID, MonitoredComponentType::Script),
|
||||||
|
Duration::from_millis(10),
|
||||||
|
Duration::from_millis(1000),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Start an activity.
|
||||||
|
let hang_annotation = HangAnnotation::Script(ScriptHangAnnotation::AttachLayout);
|
||||||
|
background_hang_monitor.notify_activity(hang_annotation);
|
||||||
|
|
||||||
|
// Unregister the component.
|
||||||
|
background_hang_monitor.unregister();
|
||||||
|
|
||||||
|
// Sleep until the "transient" timeout has been reached.
|
||||||
|
thread::sleep(Duration::from_millis(10));
|
||||||
|
|
||||||
|
// No new alert yet
|
||||||
|
assert!(background_hang_monitor_receiver.try_recv().is_err());
|
||||||
|
}
|
||||||
|
|
|
@ -926,6 +926,7 @@ impl LayoutThread {
|
||||||
self.root_flow.borrow_mut().take();
|
self.root_flow.borrow_mut().take();
|
||||||
// Drop the rayon threadpool if present.
|
// Drop the rayon threadpool if present.
|
||||||
let _ = self.parallel_traversal.take();
|
let _ = self.parallel_traversal.take();
|
||||||
|
self.background_hang_monitor.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_add_stylesheet(&self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard) {
|
fn handle_add_stylesheet(&self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard) {
|
||||||
|
|
|
@ -469,4 +469,6 @@ pub trait BackgroundHangMonitor {
|
||||||
fn notify_activity(&self, annotation: HangAnnotation);
|
fn notify_activity(&self, annotation: HangAnnotation);
|
||||||
/// Notify the start of waiting for a new event to come in.
|
/// Notify the start of waiting for a new event to come in.
|
||||||
fn notify_wait(&self);
|
fn notify_wait(&self);
|
||||||
|
/// Unregister the component from monitor.
|
||||||
|
fn unregister(&self);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2379,6 +2379,8 @@ impl ScriptThread {
|
||||||
self.handle_exit_pipeline_msg(pipeline_id, DiscardBrowsingContext::Yes);
|
self.handle_exit_pipeline_msg(pipeline_id, DiscardBrowsingContext::Yes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.background_hang_monitor.unregister();
|
||||||
|
|
||||||
debug!("Exited script thread.");
|
debug!("Exited script thread.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue