Move yunq to new thread spawn and remove old one.

This commit is contained in:
Drew Galbraith 2025-01-26 00:05:55 -08:00
parent 79e1ea2791
commit d777b8f4ab
7 changed files with 33 additions and 76 deletions

View file

@ -1,7 +1,9 @@
use core::cell::RefCell;
use alloc::rc::Rc;
use alloc::sync::Arc;
use alloc::{collections::BTreeMap, string::String};
use mammoth::sync::Mutex;
use mammoth::{cap::Capability, mem::MemoryRegion, zion::ZError};
use victoriafalls::VFSClient;
use yellowstone_yunq::{
@ -15,7 +17,7 @@ pub struct YellowstoneServerContext {
registration_semaphore: mammoth::sync::Semaphore,
pci_reader: PciReader,
framebuffer_info_region: MemoryRegion,
service_map: RefCell<BTreeMap<String, Capability>>,
service_map: Mutex<BTreeMap<String, Capability>>,
}
impl YellowstoneServerContext {
@ -52,13 +54,13 @@ impl YellowstoneServerContext {
registration_semaphore: mammoth::sync::Semaphore::new()?,
pci_reader: PciReader::new(pci_region),
framebuffer_info_region: fb_region,
service_map: BTreeMap::new().into(),
service_map: Mutex::new(BTreeMap::new()),
})
}
pub fn wait(&self, service: &str) -> Result<(), ZError> {
loop {
match self.service_map.borrow().get(service) {
match self.service_map.lock().get(service) {
Some(_) => return Ok(()),
None => {}
}
@ -68,11 +70,11 @@ impl YellowstoneServerContext {
}
pub struct YellowstoneServerImpl {
context: Rc<YellowstoneServerContext>,
context: Arc<YellowstoneServerContext>,
}
impl YellowstoneServerImpl {
pub fn new(context: Rc<YellowstoneServerContext>) -> Self {
pub fn new(context: Arc<YellowstoneServerContext>) -> Self {
Self { context }
}
}
@ -87,7 +89,7 @@ impl YellowstoneServerHandler for YellowstoneServerImpl {
self.context
.service_map
.borrow_mut()
.lock()
.insert(req.endpoint_name, Capability::take(req.endpoint_capability));
self.context.registration_semaphore.signal()?;
@ -95,7 +97,7 @@ impl YellowstoneServerHandler for YellowstoneServerImpl {
}
fn get_endpoint(&mut self, req: GetEndpointRequest) -> Result<Endpoint, ZError> {
match self.context.service_map.borrow().get(&req.endpoint_name) {
match self.context.service_map.lock().get(&req.endpoint_name) {
Some(cap) => Ok(Endpoint {
endpoint: cap.duplicate(Capability::PERMS_ALL)?.release(),
}),
@ -122,7 +124,7 @@ impl YellowstoneServerHandler for YellowstoneServerImpl {
}
fn get_denali(&mut self) -> Result<DenaliInfo, ZError> {
match self.context.service_map.borrow().get("denali") {
match self.context.service_map.lock().get("denali") {
Some(ep_cap) => crate::gpt::read_gpt(denali::DenaliClient::new(
ep_cap.duplicate(Capability::PERMS_ALL).unwrap(),
))