hoist net thread exhaustion check to before we check the poll interval

This commit is contained in:
bunnie 2022-05-06 04:00:20 +08:00
parent fd2aa438c0
commit 2a4dd67564

View file

@ -1580,6 +1580,7 @@ fn xmain() -> ! {
} }
// establish our next check-up interval // establish our next check-up interval
if delay_threads.load(Ordering::SeqCst) < MAX_DELAY_THREADS {
let timestamp = Instant::from_millis(timer.elapsed_ms() as i64); let timestamp = Instant::from_millis(timer.elapsed_ms() as i64);
if let Some(delay) = iface.poll_delay(&sockets, timestamp) { if let Some(delay) = iface.poll_delay(&sockets, timestamp) {
let delay_ms = delay.total_millis(); let delay_ms = delay.total_millis();
@ -1590,7 +1591,6 @@ fn xmain() -> ! {
) )
.ok(); .ok();
} else { } else {
if delay_threads.load(Ordering::SeqCst) < MAX_DELAY_THREADS {
let prev_count = delay_threads.fetch_add(1, Ordering::SeqCst); let prev_count = delay_threads.fetch_add(1, Ordering::SeqCst);
log::trace!( log::trace!(
"spawning checkup thread for {}ms. New total threads: {}", "spawning checkup thread for {}ms. New total threads: {}",
@ -1621,10 +1621,17 @@ fn xmain() -> ! {
); );
} }
}); });
}
}
} else { } else {
log::warn!("Could not queue delay of {}ms in net stack due to thread exhaustion.", delay_ms); log::warn!("Thread pool exhausted; deferring creation of new poll helpers");
} // fire off another pump message. This will cause the network server to effectively
} // busy-wait until the thread pool starts to clear out.
xous::try_send_message(
net_conn,
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0),
)
.ok();
} }
} }
Some(Opcode::GetIpv4Config) => { Some(Opcode::GetIpv4Config) => {