add a thread to respond to suspend requests on the connection manager

the connection manager actually wants a ping on resume,
and when we suspend we suspend -- "it is what it is". However,
the connection manager is a hairball that can block for a while,
so, to prevent failures to suspend, we put the suspend listener
in its own thread, and on resume the suspend listener will
automagically kick out an event to tell the connection manager
to deal with stuff.
This commit is contained in:
bunnie 2022-03-30 02:29:09 +08:00
parent d8065b76df
commit 6a6c2aef0f

View file

@ -131,9 +131,30 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
}
});
let mut susres = susres::Susres::new(
Some(susres::SuspendOrder::Late), &xns,
ConnectionManagerOpcode::SuspendResume as u32, self_cid).expect("couldn't create suspend/resume object");
// this thread ensures that the connection manager does not become a blocking item for a suspend
// sometimes the connection manager can get stuck in very long ops, which will need to be restarted anyways
// on resume.
let _ = std::thread::spawn({
let main_cid: u32 = self_cid;
move || {
let sus_server = xous::create_server().unwrap();
let sus_cid = xous::connect(sus_server).unwrap();
let mut susres = susres::Susres::new(
Some(susres::SuspendOrder::Late), &xns,
0, sus_cid).expect("couldn't create suspend/resume object");
loop {
let msg = xous::receive_message(sus_server).unwrap();
xous::msg_scalar_unpack!(msg, token, _, _, _, {
// for now, nothing to do to prepare for suspend...
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
// but on resume, kick a message to the main loop to tell it to recheck its connections!
xous::send_message(main_cid,
Message::new_scalar(ConnectionManagerOpcode::SuspendResume.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't send the resume message to the main thread");
});
}
}
});
com.set_ssid_scanning(true).unwrap(); // kick off an initial SSID scan, we'll always want this info regardless
let mut scan_state = SsidScanState::Scanning;
@ -143,10 +164,9 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
let mut msg = xous::receive_message(sid).unwrap();
log::debug!("got msg: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(ConnectionManagerOpcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
// for now, nothing to do to prepare for suspend...
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
// on resume, check with the EC and see where the link state ended up
Some(ConnectionManagerOpcode::SuspendResume) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
// this doesn't follow the usual "suspender" pattern. In fact, we don't do anything special on suspend;
// however, on resume, check with the EC and see where the link state ended up.
let (res_linkstate, _res_dhcpstate) = com.wlan_sync_state().unwrap();
match res_linkstate {
LinkState::Connected => {