mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
eliminate yield loop on blocking mount poller
This commit is contained in:
parent
b75df1efb3
commit
92c6a93147
3 changed files with 23 additions and 24 deletions
|
|
@ -107,7 +107,7 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
|
|||
move || {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let pddb = pddb::Pddb::new();
|
||||
pddb.is_mounted_blocking(None);
|
||||
pddb.is_mounted_blocking();
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ pub struct Pddb {
|
|||
/// like this are probably OK.
|
||||
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send> >>>,
|
||||
trng: trng::Trng,
|
||||
tt: ticktimer_server::Ticktimer,
|
||||
}
|
||||
impl Pddb {
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -127,32 +126,21 @@ impl Pddb {
|
|||
cb_handle: Some(handle),
|
||||
keys,
|
||||
trng: trng::Trng::new(&xns).unwrap(),
|
||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||
}
|
||||
}
|
||||
/// This call "sometimes blocks". It will block when the PDDB is busy performing other tasks, such as
|
||||
/// mounting the PDDB, or requesting the user's password.
|
||||
pub fn is_mounted_maybe_blocking(&self) -> bool {
|
||||
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
||||
Opcode::IsMounted.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
||||
match ret {
|
||||
xous::Result::Scalar1(code) => {
|
||||
if code == 0 {false} else {true}
|
||||
},
|
||||
_ => panic!("Internal error"),
|
||||
}
|
||||
}
|
||||
/// This blocks until the PDDB is mounted by the end user. If `None` is specified for the poll_interval_ms,
|
||||
/// A random interval between 1 and 2 seconds is chosen for the poll wait time. Randomizing the waiting time
|
||||
/// helps to level out the task scheduler in the case that many threads are waiting on the PDDB simultaneously.
|
||||
pub fn is_mounted_blocking(&self, poll_interval_ms: Option<u32>) {
|
||||
let interval = if let Some(i) = poll_interval_ms {
|
||||
i
|
||||
} else {
|
||||
(self.trng.get_u32().unwrap() % 1000) + 1000
|
||||
};
|
||||
while !self.is_mounted_maybe_blocking() {
|
||||
self.tt.sleep_ms(interval as usize).unwrap();
|
||||
///
|
||||
/// This is typically the API call one would use to hold execution of a service until the PDDB is mounted.
|
||||
pub fn is_mounted_blocking(&self) {
|
||||
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
||||
Opcode::IsMounted.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
||||
match ret {
|
||||
xous::Result::Scalar1(_code) => {
|
||||
()
|
||||
},
|
||||
_ => panic!("Internal error"),
|
||||
}
|
||||
}
|
||||
pub fn try_mount(&self) -> bool {
|
||||
|
|
|
|||
|
|
@ -518,6 +518,9 @@ fn xmain() -> ! {
|
|||
// it is the only server capable of doing this.
|
||||
let time_resetter = xns.request_connection_blocking(crate::TIME_SERVER_PDDB).unwrap();
|
||||
|
||||
// track processes that want a notification of a mount event
|
||||
let mut mount_notifications = Vec::<xous::MessageSender>::new();
|
||||
|
||||
// register a suspend/resume listener
|
||||
let mut susres = susres::Susres::new(Some(susres::SuspendOrder::Early), &xns,
|
||||
Opcode::SuspendResume as u32, my_cid).expect("couldn't create suspend/resume object");
|
||||
|
|
@ -532,7 +535,7 @@ fn xmain() -> ! {
|
|||
if basis_cache.basis_count() > 0 { // if there's anything in the cache, we're mounted.
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||
} else {
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||
mount_notifications.push(msg.sender); // defer response until later
|
||||
}
|
||||
}),
|
||||
Some(Opcode::TryMount) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
|
|
@ -547,6 +550,10 @@ fn xmain() -> ! {
|
|||
PasswordState::Correct => {
|
||||
if try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache, PasswordState::Correct, time_resetter) {
|
||||
is_mounted.store(true, Ordering::SeqCst);
|
||||
for requester in mount_notifications.drain(..) {
|
||||
xous::return_scalar(requester, 1).expect("couldn't return scalar");
|
||||
}
|
||||
assert!(mount_notifications.len() == 0, "apparently I don't understand what drain() does");
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||
} else {
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||
|
|
@ -555,6 +562,10 @@ fn xmain() -> ! {
|
|||
PasswordState::Uninit => {
|
||||
if try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache, PasswordState::Uninit, time_resetter) {
|
||||
is_mounted.store(true, Ordering::SeqCst);
|
||||
for requester in mount_notifications.drain(..) {
|
||||
xous::return_scalar(requester, 1).expect("couldn't return scalar");
|
||||
}
|
||||
assert!(mount_notifications.len() == 0, "apparently I don't understand what drain() does");
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||
} else {
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||
|
|
|
|||
Loading…
Reference in a new issue