mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-25 09:26:17 +04:00
Some code cleanup
This commit is contained in:
parent
21f024c76d
commit
6a0e25431b
@ -16,11 +16,12 @@ impl<T: FrameAllocator> SharedGuard<T> {
|
||||
pub fn new(allocator: T) -> Self {
|
||||
SharedGuard {
|
||||
allocator: allocator,
|
||||
// size meaningful only for sys_shm
|
||||
size: 0,
|
||||
target: BTreeMap::new(),
|
||||
}
|
||||
// size meaningful only for sys_shm
|
||||
}
|
||||
|
||||
pub fn new_with_size(allocator: T, size: usize) -> Self {
|
||||
SharedGuard {
|
||||
allocator: allocator,
|
||||
@ -28,22 +29,24 @@ impl<T: FrameAllocator> SharedGuard<T> {
|
||||
target: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc(&mut self, virt_addr: usize) -> Option<usize> {
|
||||
let phys_addr = self.allocator.alloc().expect("failed to allocate frame");
|
||||
self.target.insert(virt_addr, phys_addr);
|
||||
Some(phys_addr)
|
||||
}
|
||||
|
||||
pub fn dealloc(&mut self, virt_addr: usize) {
|
||||
let phys_addr = self.target.get(&virt_addr).unwrap().clone();
|
||||
self.allocator.dealloc(phys_addr);
|
||||
self.target.remove(&virt_addr);
|
||||
}
|
||||
|
||||
pub fn get(&self, addr: usize) -> Option<usize> {
|
||||
match self.target.get(&addr) {
|
||||
Some(phys_addr) => Some(phys_addr.clone()),
|
||||
None => None,
|
||||
}
|
||||
//Some(self.target.get(&addr).unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +134,7 @@ impl<T: FrameAllocator> MemoryHandler for Shared<T> {
|
||||
entry.set_present(true);
|
||||
entry.update();
|
||||
|
||||
//init with zero for delay mmap mode
|
||||
// init with zero for delay mmap mode
|
||||
let data = pt.get_page_slice_mut(addr);
|
||||
let len = data.len();
|
||||
for x in data {
|
||||
@ -157,6 +160,7 @@ impl<T: FrameAllocator> Shared<T> {
|
||||
guard: Arc::new(Mutex::new(SharedGuard::new(allocator))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_guard(allocator: T, guard: Arc<Mutex<SharedGuard<T>>>) -> Self {
|
||||
Shared {
|
||||
allocator: allocator.clone(),
|
||||
|
@ -42,14 +42,17 @@ impl SemProc {
|
||||
self.arrays.insert(id, array);
|
||||
id
|
||||
}
|
||||
|
||||
/// Get a free ID
|
||||
fn get_free_id(&self) -> SemId {
|
||||
(0..).find(|i| self.arrays.get(i).is_none()).unwrap()
|
||||
}
|
||||
|
||||
/// Get an semaphore set by `id`
|
||||
pub fn get(&self, id: SemId) -> Option<Arc<SemArray>> {
|
||||
self.arrays.get(&id).map(|a| a.clone())
|
||||
}
|
||||
|
||||
/// Add an undo operation
|
||||
pub fn add_undo(&mut self, id: SemId, num: SemNum, op: SemOp) {
|
||||
let old_val = *self.undos.get(&(id, num)).unwrap_or(&0);
|
||||
@ -95,12 +98,14 @@ impl ShmProc {
|
||||
self.shm_identifiers.insert(id, shm_identifier);
|
||||
id
|
||||
}
|
||||
|
||||
/// Get a free ID
|
||||
fn get_free_id(&self) -> ShmId {
|
||||
(0..)
|
||||
.find(|i| self.shm_identifiers.get(i).is_none())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Get an semaphore set by `id`
|
||||
pub fn get(&self, id: ShmId) -> Option<ShmIdentifier> {
|
||||
self.shm_identifiers.get(&id).map(|a| a.clone())
|
||||
@ -120,6 +125,7 @@ impl ShmProc {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Pop Shared Area
|
||||
pub fn pop(&mut self, id: ShmId) {
|
||||
self.shm_identifiers.remove(&id);
|
||||
|
@ -363,11 +363,6 @@ impl Syscall<'_> {
|
||||
SYS_SHMAT => self.sys_shmat(args[0], args[1], args[2]),
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
SYS_SHMDT => self.sys_shmdt(args[0], args[1], args[2]),
|
||||
/*SYS_SHMCTL => self.sys_shmctl(
|
||||
args[0],
|
||||
args[1],
|
||||
args[2] /* should be shmid_ds *buf */
|
||||
),*/
|
||||
// system
|
||||
SYS_GETPID => self.sys_getpid(),
|
||||
SYS_GETTID => self.sys_gettid(),
|
||||
|
Loading…
Reference in New Issue
Block a user