generic channel: Migrate background hang monitor to GenericChannel (#39345)

Refactor the background hang monitor channels to use GenericChannel. 
Deserialization errors of `BackgroundHangMonitorControlMsg` are now
logged and ignored instead of causing a panic.

Testing: No major functional changes. Covered by BHM tests.
GenericChannel is also already widely used in servo.
Part of #38912

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2025-09-17 19:11:07 +08:00 committed by GitHub
parent 6cba44e0e3
commit d848bd2759
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 31 deletions

View file

@ -309,15 +309,15 @@ pub struct Constellation<STF, SWF> {
/// Channels to control all background-hang monitors.
/// TODO: store them on the relevant BrowsingContextGroup,
/// so that they could be controlled on a "per-tab/event-loop" basis.
background_monitor_control_senders: Vec<IpcSender<BackgroundHangMonitorControlMsg>>,
background_monitor_control_senders: Vec<GenericSender<BackgroundHangMonitorControlMsg>>,
/// A channel for the background hang monitor to send messages
/// to the constellation.
background_hang_monitor_sender: IpcSender<HangMonitorAlert>,
background_hang_monitor_sender: GenericSender<HangMonitorAlert>,
/// A channel for the constellation to receiver messages
/// from the background hang monitor.
background_hang_monitor_receiver: Receiver<Result<HangMonitorAlert, IpcError>>,
background_hang_monitor_receiver: RoutedReceiver<HangMonitorAlert>,
/// A factory for creating layouts. This allows customizing the kind
/// of layout created for a [`Constellation`] and prevents a circular crate
@ -627,11 +627,9 @@ where
let namespace_receiver = namespace_ipc_receiver.route_preserving_errors();
let (background_hang_monitor_ipc_sender, background_hang_monitor_ipc_receiver) =
ipc::channel().expect("ipc channel failure");
generic_channel::channel().expect("ipc channel failure");
let background_hang_monitor_receiver =
route_ipc_receiver_to_new_crossbeam_receiver_preserving_errors(
background_hang_monitor_ipc_receiver,
);
background_hang_monitor_ipc_receiver.route_preserving_errors();
// If we are in multiprocess mode,
// a dedicated per-process hang monitor will be initialized later inside the content process.
@ -646,7 +644,7 @@ where
let (
background_hang_monitor_control_ipc_sender,
background_hang_monitor_control_ipc_receiver,
) = ipc::channel().expect("ipc channel failure");
) = generic_channel::channel().expect("ipc channel failure");
let (register, join_handle) = HangMonitorRegister::init(
background_hang_monitor_ipc_sender.clone(),
background_hang_monitor_control_ipc_receiver,