mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
Refactor Rwlock to take type parameter
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ac1a6be05d
commit
495c93c2ad
@ -9,7 +9,7 @@ use log::debug;
|
||||
use ostd::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaDirection, DmaStream, DmaStreamSlice, FrameAllocOptions, VmReader},
|
||||
sync::{RwLock, SpinLock},
|
||||
sync::{LocalIrqDisabled, RwLock, SpinLock},
|
||||
trap::TrapFrame,
|
||||
};
|
||||
|
||||
@ -27,7 +27,7 @@ pub struct ConsoleDevice {
|
||||
transmit_queue: SpinLock<VirtQueue>,
|
||||
send_buffer: DmaStream,
|
||||
receive_buffer: DmaStream,
|
||||
callbacks: RwLock<Vec<&'static ConsoleCallback>>,
|
||||
callbacks: RwLock<Vec<&'static ConsoleCallback>, LocalIrqDisabled>,
|
||||
}
|
||||
|
||||
impl AnyConsoleDevice for ConsoleDevice {
|
||||
@ -54,7 +54,7 @@ impl AnyConsoleDevice for ConsoleDevice {
|
||||
}
|
||||
|
||||
fn register_callback(&self, callback: &'static ConsoleCallback) {
|
||||
self.callbacks.write_irq_disabled().push(callback);
|
||||
self.callbacks.write().push(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ impl ConsoleDevice {
|
||||
};
|
||||
self.receive_buffer.sync(0..len as usize).unwrap();
|
||||
|
||||
let callbacks = self.callbacks.read_irq_disabled();
|
||||
let callbacks = self.callbacks.read();
|
||||
for callback in callbacks.iter() {
|
||||
let reader = self.receive_buffer.reader().unwrap().limit(len as usize);
|
||||
callback(reader);
|
||||
|
@ -19,7 +19,7 @@ use ostd::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaDirection, DmaStream, FrameAllocOptions, HasDaddr, VmIo, PAGE_SIZE},
|
||||
offset_of,
|
||||
sync::{RwLock, SpinLock},
|
||||
sync::{LocalIrqDisabled, RwLock, SpinLock},
|
||||
trap::TrapFrame,
|
||||
};
|
||||
|
||||
@ -76,7 +76,7 @@ pub struct InputDevice {
|
||||
status_queue: VirtQueue,
|
||||
event_table: EventTable,
|
||||
#[allow(clippy::type_complexity)]
|
||||
callbacks: RwLock<Vec<Arc<dyn Fn(InputEvent) + Send + Sync + 'static>>>,
|
||||
callbacks: RwLock<Vec<Arc<dyn Fn(InputEvent) + Send + Sync + 'static>>, LocalIrqDisabled>,
|
||||
transport: SpinLock<Box<dyn VirtioTransport>>,
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ impl InputDevice {
|
||||
}
|
||||
|
||||
fn handle_irq(&self) {
|
||||
let callbacks = self.callbacks.read_irq_disabled();
|
||||
let callbacks = self.callbacks.read();
|
||||
// Returns true if there may be more events to handle
|
||||
let handle_event = |event: &EventBuf| -> bool {
|
||||
event.sync().unwrap();
|
||||
@ -295,7 +295,7 @@ impl<T, M: HasDaddr> DmaBuf for SafePtr<T, M> {
|
||||
|
||||
impl aster_input::InputDevice for InputDevice {
|
||||
fn register_callbacks(&self, function: &'static (dyn Fn(InputEvent) + Send + Sync)) {
|
||||
self.callbacks.write_irq_disabled().push(Arc::new(function))
|
||||
self.callbacks.write().push(Arc::new(function))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user