use crate::msi::MsiControl;
use crate::msi::MsiInterruptTarget;
use parking_lot::Mutex;
use std::collections::VecDeque;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct TestPciInterruptController {
inner: Arc<TestPciInterruptControllerInner>,
}
#[derive(Debug)]
struct TestPciInterruptControllerInner {
msi_requests: Mutex<VecDeque<(u64, u32)>>, }
impl TestPciInterruptController {
pub fn new() -> Self {
Self {
inner: Arc::new(TestPciInterruptControllerInner {
msi_requests: Mutex::new(VecDeque::new()),
}),
}
}
pub fn get_next_interrupt(&self) -> Option<(u64, u32)> {
self.inner.msi_requests.lock().pop_front()
}
}
impl MsiInterruptTarget for TestPciInterruptController {
fn new_interrupt(&self) -> Box<dyn MsiControl> {
let controller = self.inner.clone();
Box::new(move |address, data| controller.msi_requests.lock().push_back((address, data)))
}
}