Make properties editable
This commit is contained in:
+16
-9
@@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Debug,
|
||||
sync::{atomic::AtomicU64, Arc, RwLock, RwLockReadGuard, TryLockError, Weak},
|
||||
sync::{atomic::AtomicU64, Arc, Mutex, RwLock, RwLockReadGuard, TryLockError, Weak},
|
||||
};
|
||||
|
||||
use bytemuck::BoxBytes;
|
||||
@@ -10,34 +10,41 @@ use tracing::warn;
|
||||
|
||||
use crate::emulator::{EmulatorClient, EmulatorCommand, SimId};
|
||||
|
||||
pub struct MemoryMonitor {
|
||||
pub struct MemoryClient {
|
||||
client: EmulatorClient,
|
||||
regions: HashMap<MemoryRange, Weak<MemoryRegion>>,
|
||||
regions: Mutex<HashMap<MemoryRange, Weak<MemoryRegion>>>,
|
||||
}
|
||||
|
||||
impl MemoryMonitor {
|
||||
impl MemoryClient {
|
||||
pub fn new(client: EmulatorClient) -> Self {
|
||||
Self {
|
||||
client,
|
||||
regions: HashMap::new(),
|
||||
regions: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&mut self, sim: SimId, start: u32, length: usize) -> MemoryView {
|
||||
pub fn watch(&self, sim: SimId, start: u32, length: usize) -> MemoryView {
|
||||
let range = MemoryRange { sim, start, length };
|
||||
let region = self
|
||||
.regions
|
||||
let mut regions = self.regions.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let region = regions
|
||||
.get(&range)
|
||||
.and_then(|r| r.upgrade())
|
||||
.unwrap_or_else(|| {
|
||||
let region = Arc::new(MemoryRegion::new(start, length));
|
||||
self.regions.insert(range, Arc::downgrade(®ion));
|
||||
regions.insert(range, Arc::downgrade(®ion));
|
||||
self.client
|
||||
.send_command(EmulatorCommand::WatchMemory(range, Arc::downgrade(®ion)));
|
||||
region
|
||||
});
|
||||
MemoryView { region }
|
||||
}
|
||||
|
||||
pub fn write<T: bytemuck::NoUninit>(&self, sim: SimId, address: u32, data: &T) {
|
||||
let data = bytemuck::bytes_of(data).to_vec();
|
||||
let (tx, _) = oneshot::channel();
|
||||
self.client
|
||||
.send_command(EmulatorCommand::WriteMemory(sim, address, data, tx));
|
||||
}
|
||||
}
|
||||
|
||||
fn aligned_memory(start: u32, length: usize) -> BoxBytes {
|
||||
|
||||
Reference in New Issue
Block a user