mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add a one-liner API call to block execution until PDDB is mounted
This commit is contained in:
parent
954840a5d0
commit
86e86df68c
1 changed files with 15 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ pub struct Pddb {
|
||||||
/// like this are probably OK.
|
/// like this are probably OK.
|
||||||
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send> >>>,
|
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send> >>>,
|
||||||
trng: trng::Trng,
|
trng: trng::Trng,
|
||||||
|
tt: ticktimer_server::Ticktimer,
|
||||||
}
|
}
|
||||||
impl Pddb {
|
impl Pddb {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
@ -86,6 +87,7 @@ impl Pddb {
|
||||||
cb_handle: Some(handle),
|
cb_handle: Some(handle),
|
||||||
keys,
|
keys,
|
||||||
trng: trng::Trng::new(&xns).unwrap(),
|
trng: trng::Trng::new(&xns).unwrap(),
|
||||||
|
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_mounted(&self) -> bool {
|
pub fn is_mounted(&self) -> bool {
|
||||||
|
|
@ -98,6 +100,19 @@ impl Pddb {
|
||||||
_ => panic!("Internal error"),
|
_ => 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() {
|
||||||
|
self.tt.sleep_ms(interval as usize).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn try_mount(&self) -> bool {
|
pub fn try_mount(&self) -> bool {
|
||||||
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
||||||
Opcode::TryMount.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
Opcode::TryMount.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue