feat(domain): add EndpointTable, IrqRoutingTable, and remaining error variants

This commit is contained in:
2026-10-17 23:51:56 +02:00
parent ed80fc43a6
commit 328708ed58
5 changed files with 170 additions and 1 deletions

View File

@@ -66,6 +66,39 @@ impl Endpoint {
}
}
const MAX_ENDPOINTS: usize = 256;
pub struct EndpointTable {
endpoints: [Option<Endpoint>; MAX_ENDPOINTS],
}
impl EndpointTable {
pub fn new() -> Self {
Self {
endpoints: [const { None }; MAX_ENDPOINTS],
}
}
pub fn create(&mut self) -> Option<EndpointId> {
let idx = self.endpoints.iter().position(|s| s.is_none())?;
let id = EndpointId::from_raw(idx as u16);
self.endpoints[idx] = Some(Endpoint::new(id));
Some(id)
}
pub fn get(&self, id: EndpointId) -> Option<&Endpoint> {
self.endpoints.get(id.raw() as usize).and_then(|s| s.as_ref())
}
pub fn get_mut(&mut self, id: EndpointId) -> Option<&mut Endpoint> {
self.endpoints.get_mut(id.raw() as usize).and_then(|s| s.as_mut())
}
pub fn destroy(&mut self, id: EndpointId) -> Option<Endpoint> {
self.endpoints.get_mut(id.raw() as usize).and_then(|s| s.take())
}
}
pub trait MessagePassing {
fn send(
&mut self,

View File

@@ -135,3 +135,46 @@ fn rendezvous_receiver_first() {
let receiver = ep.dequeue_receiver().unwrap();
assert_eq!(receiver, thread(1));
}
// --- EndpointTable tests ---
#[test]
fn table_create_and_lookup() {
let mut table = EndpointTable::new();
let id = table.create().unwrap();
assert!(table.get(id).is_some());
}
#[test]
fn table_create_returns_unique_ids() {
let mut table = EndpointTable::new();
let a = table.create().unwrap();
let b = table.create().unwrap();
assert_ne!(a, b);
}
#[test]
fn table_destroy_then_get_fails() {
let mut table = EndpointTable::new();
let id = table.create().unwrap();
let removed = table.destroy(id);
assert!(removed.is_some());
assert!(table.get(id).is_none());
}
#[test]
fn table_get_mut_allows_enqueue() {
let mut table = EndpointTable::new();
let id = table.create().unwrap();
table.get_mut(id).unwrap().enqueue_sender(thread(1)).unwrap();
assert!(table.get(id).unwrap().has_waiting_sender());
}
#[test]
fn table_destroy_reuses_slot() {
let mut table = EndpointTable::new();
let id = table.create().unwrap();
table.destroy(id);
let new_id = table.create().unwrap();
assert_eq!(id, new_id);
}