xous-core/libs/chat/src/main.rs
bunnie b456bfaf3b add busy-wait animation server and hooks for managing the same
Busy-wait animaitions are handled by a helper server that is normally
blocked. A single shared `bool` indicates whether the animation should
run or not.

When woken up, the busy-wait animator will check if the shared `bool`
is set, and if so, send a message to the main loop to update
the animation, then send wait an appropriate timeout and send itself
a message to re-check the animation status.

This particular format of server is fairly compact but can be vulnerable
to a "message storm" if busy state updates happen in rapid
succession without allowing the server to unblock and handle messages.
Thus, all messages to this server use a `try_send` method, with a silent
failure if the message can't be sent. In other words, if the animator
is already super busy and its queue is full, don't send it more messages,
just drop the existing updates so we can fail without a panic or deadlock.
The typical consequence of this is some UX inconsistency, which is
not a critical error.
2023-10-20 00:43:09 +08:00

41 lines
1.2 KiB
Rust

#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
mod api;
use api::*;
use num_traits::FromPrimitive;
use std::thread;
use xous::{Error, CID, SID};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
pub fn main() -> ! {
let xns = xous_names::XousNames::new().unwrap();
let sid = xns
.register_name("Chat UI", None)
.expect("can't register server");
log::trace!("registered with NS -- {:?}", sid);
let chat_sid = xous::create_server().unwrap();
let chat_cid = xous::connect(chat_sid).unwrap();
let busy_bumper = xous::create_server().unwrap();
let busy_bumper_cid = xous::connect(busy_bumper).unwrap();
log::info!("starting idle animation runner");
let run_busy_animation = Arc::new(AtomicBool::new(false));
thread::spawn({
let run_busy_animation = run_busy_animation.clone();
move || {
busy_animator(busy_bumper, busy_bumper_cid, chat_cid, run_busy_animation);
}
});
log::info!("Starting chat server",);
thread::spawn({
move || {
server(chat_sid, None, None, run_busy_animation, busy_bumper_cid);
}
});
xous::terminate_process(0)
}