fix: missing thread name when spawning (#31656)

* Add missing thread name when spawning

* Update namings
This commit is contained in:
Ngo Iok Ui (Wu Yu Wei) 2024-03-14 19:40:58 +09:00 committed by GitHub
parent 78fe461ff2
commit b1debf2068
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 28 deletions

View file

@ -49,6 +49,7 @@ impl HangMonitorRegister {
let (tether, tether_port) = unbounded(); let (tether, tether_port) = unbounded();
let _ = thread::Builder::new() let _ = thread::Builder::new()
.name("BackgroundHangMonitor".to_owned())
.spawn(move || { .spawn(move || {
let mut monitor = BackgroundHangMonitorWorker::new( let mut monitor = BackgroundHangMonitorWorker::new(
constellation_chan, constellation_chan,

View file

@ -526,6 +526,7 @@ pub struct CoreResourceThreadPool {
impl CoreResourceThreadPool { impl CoreResourceThreadPool {
pub fn new(num_threads: usize) -> CoreResourceThreadPool { pub fn new(num_threads: usize) -> CoreResourceThreadPool {
let pool = rayon::ThreadPoolBuilder::new() let pool = rayon::ThreadPoolBuilder::new()
.thread_name(|i| format!("CoreResourceThread#{i}"))
.num_threads(num_threads) .num_threads(num_threads)
.build() .build()
.unwrap(); .unwrap();

View file

@ -291,9 +291,9 @@ impl WorkletThreadPool {
primary_sender: primary_sender, primary_sender: primary_sender,
hot_backup_sender: hot_backup_sender, hot_backup_sender: hot_backup_sender,
cold_backup_sender: cold_backup_sender, cold_backup_sender: cold_backup_sender,
control_sender_0: WorkletThread::spawn(primary_role, init.clone()), control_sender_0: WorkletThread::spawn(primary_role, init.clone(), 0),
control_sender_1: WorkletThread::spawn(hot_backup_role, init.clone()), control_sender_1: WorkletThread::spawn(hot_backup_role, init.clone(), 1),
control_sender_2: WorkletThread::spawn(cold_backup_role, init), control_sender_2: WorkletThread::spawn(cold_backup_role, init, 2),
} }
} }
@ -464,32 +464,38 @@ impl WorkletThread {
/// Spawn a new worklet thread, returning the channel to send it control messages. /// Spawn a new worklet thread, returning the channel to send it control messages.
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
fn spawn(role: WorkletThreadRole, init: WorkletThreadInit) -> Sender<WorkletControl> { fn spawn(
role: WorkletThreadRole,
init: WorkletThreadInit,
thread_index: u8,
) -> Sender<WorkletControl> {
let (control_sender, control_receiver) = unbounded(); let (control_sender, control_receiver) = unbounded();
// TODO: name this thread let _ = thread::Builder::new()
thread::spawn(move || { .name(format!("Worklet#{thread_index}"))
// TODO: add a new IN_WORKLET thread state? .spawn(move || {
// TODO: set interrupt handler? // TODO: add a new IN_WORKLET thread state?
// TODO: configure the JS runtime (e.g. discourage GC, encourage agressive JIT) // TODO: set interrupt handler?
debug!("Initializing worklet thread."); // TODO: configure the JS runtime (e.g. discourage GC, encourage agressive JIT)
thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER); debug!("Initializing worklet thread.");
let roots = RootCollection::new(); thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER);
let _stack_roots = ThreadLocalStackRoots::new(&roots); let roots = RootCollection::new();
let mut thread = RootedTraceableBox::new(WorkletThread { let _stack_roots = ThreadLocalStackRoots::new(&roots);
role: role, let mut thread = RootedTraceableBox::new(WorkletThread {
control_receiver: control_receiver, role: role,
primary_sender: init.primary_sender, control_receiver: control_receiver,
hot_backup_sender: init.hot_backup_sender, primary_sender: init.primary_sender,
cold_backup_sender: init.cold_backup_sender, hot_backup_sender: init.hot_backup_sender,
global_init: init.global_init, cold_backup_sender: init.cold_backup_sender,
global_scopes: HashMap::new(), global_init: init.global_init,
control_buffer: None, global_scopes: HashMap::new(),
runtime: new_rt_and_cx(None), control_buffer: None,
should_gc: false, runtime: new_rt_and_cx(None),
gc_threshold: MIN_GC_THRESHOLD, should_gc: false,
}); gc_threshold: MIN_GC_THRESHOLD,
thread.run(); });
}); thread.run();
})
.expect("Couldn't start worklet thread");
control_sender control_sender
} }