Implement Clone for IrqAllocateHandle

This commit is contained in:
Yuke Peng 2023-08-10 16:11:21 +08:00 committed by Tate, Hongliang Tian
parent 50c10653fb
commit 739eb30138

View File

@ -39,7 +39,7 @@ pub struct IrqAllocateHandle {
impl IrqAllocateHandle {
fn new(irq_num: u8) -> Self {
Self {
irq_num: irq_num,
irq_num,
irq: unsafe { IrqLine::acquire(irq_num) },
callbacks: Vec::new(),
}
@ -65,9 +65,21 @@ impl IrqAllocateHandle {
}
}
impl Clone for IrqAllocateHandle {
fn clone(&self) -> Self {
Self {
irq_num: self.irq_num.clone(),
irq: self.irq.clone(),
callbacks: Vec::new(),
}
}
}
impl Drop for IrqAllocateHandle {
fn drop(&mut self) {
NOT_USING_IRQ.lock().dealloc(self.irq_num as usize);
if Arc::strong_count(&self.irq) == 1 {
NOT_USING_IRQ.lock().dealloc(self.irq_num as usize);
}
}
}