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

@ -12,7 +12,7 @@ use background_hang_monitor_api::{
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, HangMonitorAlert,
};
use base::Epoch;
use base::generic_channel::{GenericReceiver, GenericSender};
use base::generic_channel::{self, GenericReceiver, GenericSender};
use base::id::{
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, WebViewId,
@ -144,7 +144,7 @@ pub struct InitialPipelineState {
pub background_monitor_register: Option<Box<dyn BackgroundHangMonitorRegister>>,
/// A channel for the background hang monitor to send messages to the constellation.
pub background_hang_monitor_to_constellation_chan: IpcSender<HangMonitorAlert>,
pub background_hang_monitor_to_constellation_chan: GenericSender<HangMonitorAlert>,
/// A fatory for creating layouts to be used by the ScriptThread.
pub layout_factory: Arc<dyn LayoutFactory>,
@ -219,7 +219,7 @@ pub struct InitialPipelineState {
pub struct NewPipeline {
pub pipeline: Pipeline,
pub bhm_control_chan: Option<IpcSender<BackgroundHangMonitorControlMsg>>,
pub bhm_control_chan: Option<GenericSender<BackgroundHangMonitorControlMsg>>,
pub lifeline: Option<(IpcReceiver<()>, Process)>,
pub join_handle: Option<JoinHandle<()>>,
}
@ -325,7 +325,7 @@ impl Pipeline {
// Yes, that's all there is to it!
let multiprocess_data = if opts::get().multiprocess {
let (bhm_control_chan, bhm_control_port) =
ipc::channel().expect("Sampler chan");
generic_channel::channel().expect("Sampler chan");
unprivileged_pipeline_content.bhm_control_port = Some(bhm_control_port);
let (sender, receiver) =
ipc::channel().expect("Failed to create lifeline channel");
@ -487,8 +487,8 @@ pub struct UnprivilegedPipelineContent {
namespace_request_sender: GenericSender<PipelineNamespaceRequest>,
script_to_constellation_chan: ScriptToConstellationChan,
script_to_embedder_chan: ScriptToEmbedderChan,
background_hang_monitor_to_constellation_chan: IpcSender<HangMonitorAlert>,
bhm_control_port: Option<IpcReceiver<BackgroundHangMonitorControlMsg>>,
background_hang_monitor_to_constellation_chan: GenericSender<HangMonitorAlert>,
bhm_control_port: Option<GenericReceiver<BackgroundHangMonitorControlMsg>>,
devtools_ipc_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
#[cfg(feature = "bluetooth")]
bluetooth_thread: IpcSender<BluetoothRequest>,