Skip to content

Commit 6aae202

Browse files
Jing Liujiangliu
Jing Liu
authored andcommitted
Make DeviceIo internal mutability
In order to get a real multiple threads handling to enhance performance, the DeviceIo trait need adopt interior mutability pattern. Signed-off-by: Jing Liu <[email protected]>
1 parent 3d51c9e commit 6aae202

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ pub enum IoAddress {
2020
/// register itself against the different IO type ranges it handles.
2121
/// The VMM will then dispatch IO (PIO or MMIO) VM exits by calling into the
2222
/// registered devices read or write method from this trait.
23+
/// The DeviceIo trait adopts the interior mutability pattern
24+
/// so we can get a real multiple threads handling.
2325
pub trait DeviceIo: Send {
2426
/// Read from the guest physical address `base`, starting at `offset`.
2527
/// Result is placed in `data`.
26-
fn read(&mut self, base: IoAddress, offset: IoAddress, data: &mut [u8]);
28+
fn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8]);
2729

2830
/// Write `data` to the guest physical address `base`, starting from `offset`.
29-
fn write(&mut self, base: IoAddress, offset: IoAddress, data: &[u8]);
31+
fn write(&self, base: IoAddress, offset: IoAddress, data: &[u8]);
3032
}

0 commit comments

Comments
 (0)