Replace SpinLock with RwLock in driver callbacks
This commit is contained in:
		
							parent
							
								
									cd1575bc6d
								
							
						
					
					
						commit
						abb377b695
					
				|  | @ -6,7 +6,7 @@ use core::hint::spin_loop; | |||
| use aster_console::{AnyConsoleDevice, ConsoleCallback}; | ||||
| use aster_frame::{ | ||||
|     io_mem::IoMem, | ||||
|     sync::SpinLock, | ||||
|     sync::{RwLock, SpinLock}, | ||||
|     trap::TrapFrame, | ||||
|     vm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader}, | ||||
| }; | ||||
|  | @ -27,7 +27,7 @@ pub struct ConsoleDevice { | |||
|     transmit_queue: SpinLock<VirtQueue>, | ||||
|     send_buffer: DmaStream, | ||||
|     receive_buffer: DmaStream, | ||||
|     callbacks: SpinLock<Vec<&'static ConsoleCallback>>, | ||||
|     callbacks: RwLock<Vec<&'static ConsoleCallback>>, | ||||
| } | ||||
| 
 | ||||
| impl AnyConsoleDevice for ConsoleDevice { | ||||
|  | @ -54,7 +54,7 @@ impl AnyConsoleDevice for ConsoleDevice { | |||
|     } | ||||
| 
 | ||||
|     fn register_callback(&self, callback: &'static ConsoleCallback) { | ||||
|         self.callbacks.lock_irq_disabled().push(callback); | ||||
|         self.callbacks.write_irq_disabled().push(callback); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -103,7 +103,7 @@ impl ConsoleDevice { | |||
|             transmit_queue, | ||||
|             send_buffer, | ||||
|             receive_buffer, | ||||
|             callbacks: SpinLock::new(Vec::new()), | ||||
|             callbacks: RwLock::new(Vec::new()), | ||||
|         }); | ||||
| 
 | ||||
|         let mut receive_queue = device.receive_queue.lock_irq_disabled(); | ||||
|  | @ -143,7 +143,7 @@ impl ConsoleDevice { | |||
|         let (_, len) = receive_queue.pop_used().unwrap(); | ||||
|         self.receive_buffer.sync(0..len as usize).unwrap(); | ||||
| 
 | ||||
|         let callbacks = self.callbacks.lock_irq_disabled(); | ||||
|         let callbacks = self.callbacks.read_irq_disabled(); | ||||
| 
 | ||||
|         for callback in callbacks.iter() { | ||||
|             let reader = self.receive_buffer.reader().unwrap().limit(len as usize); | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ use core::{fmt::Debug, mem}; | |||
| use aster_frame::{ | ||||
|     io_mem::IoMem, | ||||
|     offset_of, | ||||
|     sync::SpinLock, | ||||
|     sync::{RwLock, SpinLock}, | ||||
|     trap::TrapFrame, | ||||
|     vm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, VmReader, PAGE_SIZE}, | ||||
| }; | ||||
|  | @ -76,7 +76,7 @@ pub struct InputDevice { | |||
|     status_queue: VirtQueue, | ||||
|     event_table: EventTable, | ||||
|     #[allow(clippy::type_complexity)] | ||||
|     callbacks: SpinLock<Vec<Arc<dyn Fn(InputEvent) + Send + Sync + 'static>>>, | ||||
|     callbacks: RwLock<Vec<Arc<dyn Fn(InputEvent) + Send + Sync + 'static>>>, | ||||
|     transport: SpinLock<Box<dyn VirtioTransport>>, | ||||
| } | ||||
| 
 | ||||
|  | @ -109,7 +109,7 @@ impl InputDevice { | |||
|             status_queue, | ||||
|             event_table, | ||||
|             transport: SpinLock::new(transport), | ||||
|             callbacks: SpinLock::new(Vec::new()), | ||||
|             callbacks: RwLock::new(Vec::new()), | ||||
|         }); | ||||
| 
 | ||||
|         let mut raw_name: [u8; 128] = [0; 128]; | ||||
|  | @ -187,6 +187,7 @@ impl InputDevice { | |||
|     } | ||||
| 
 | ||||
|     fn handle_irq(&self) { | ||||
|         let callbacks = self.callbacks.read_irq_disabled(); | ||||
|         // Returns ture if there may be more events to handle
 | ||||
|         let handle_event = |event: &EventBuf| -> bool { | ||||
|             let event: VirtioInputEvent = { | ||||
|  | @ -211,7 +212,6 @@ impl InputDevice { | |||
|             let event = InputEvent::KeyBoard(Key::try_from(event.code).unwrap(), status); | ||||
|             info!("Input Event:{:?}", event); | ||||
| 
 | ||||
|             let callbacks = self.callbacks.lock(); | ||||
|             for callback in callbacks.iter() { | ||||
|                 callback(event); | ||||
|             } | ||||
|  | @ -307,7 +307,7 @@ impl<'a> EventBuf<'a> { | |||
| 
 | ||||
| impl aster_input::InputDevice for InputDevice { | ||||
|     fn register_callbacks(&self, function: &'static (dyn Fn(InputEvent) + Send + Sync)) { | ||||
|         self.callbacks.lock_irq_disabled().push(Arc::new(function)) | ||||
|         self.callbacks.write_irq_disabled().push(Arc::new(function)) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue