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 {
|
pub fn new(allocator: T) -> Self {
|
||||||
SharedGuard {
|
SharedGuard {
|
||||||
allocator: allocator,
|
allocator: allocator,
|
||||||
|
// size meaningful only for sys_shm
|
||||||
size: 0,
|
size: 0,
|
||||||
target: BTreeMap::new(),
|
target: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
// size meaningful only for sys_shm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_size(allocator: T, size: usize) -> Self {
|
pub fn new_with_size(allocator: T, size: usize) -> Self {
|
||||||
SharedGuard {
|
SharedGuard {
|
||||||
allocator: allocator,
|
allocator: allocator,
|
||||||
@ -28,22 +29,24 @@ impl<T: FrameAllocator> SharedGuard<T> {
|
|||||||
target: BTreeMap::new(),
|
target: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alloc(&mut self, virt_addr: usize) -> Option<usize> {
|
pub fn alloc(&mut self, virt_addr: usize) -> Option<usize> {
|
||||||
let phys_addr = self.allocator.alloc().expect("failed to allocate frame");
|
let phys_addr = self.allocator.alloc().expect("failed to allocate frame");
|
||||||
self.target.insert(virt_addr, phys_addr);
|
self.target.insert(virt_addr, phys_addr);
|
||||||
Some(phys_addr)
|
Some(phys_addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dealloc(&mut self, virt_addr: usize) {
|
pub fn dealloc(&mut self, virt_addr: usize) {
|
||||||
let phys_addr = self.target.get(&virt_addr).unwrap().clone();
|
let phys_addr = self.target.get(&virt_addr).unwrap().clone();
|
||||||
self.allocator.dealloc(phys_addr);
|
self.allocator.dealloc(phys_addr);
|
||||||
self.target.remove(&virt_addr);
|
self.target.remove(&virt_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, addr: usize) -> Option<usize> {
|
pub fn get(&self, addr: usize) -> Option<usize> {
|
||||||
match self.target.get(&addr) {
|
match self.target.get(&addr) {
|
||||||
Some(phys_addr) => Some(phys_addr.clone()),
|
Some(phys_addr) => Some(phys_addr.clone()),
|
||||||
None => None,
|
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.set_present(true);
|
||||||
entry.update();
|
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 data = pt.get_page_slice_mut(addr);
|
||||||
let len = data.len();
|
let len = data.len();
|
||||||
for x in data {
|
for x in data {
|
||||||
@ -157,6 +160,7 @@ impl<T: FrameAllocator> Shared<T> {
|
|||||||
guard: Arc::new(Mutex::new(SharedGuard::new(allocator))),
|
guard: Arc::new(Mutex::new(SharedGuard::new(allocator))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_guard(allocator: T, guard: Arc<Mutex<SharedGuard<T>>>) -> Self {
|
pub fn new_with_guard(allocator: T, guard: Arc<Mutex<SharedGuard<T>>>) -> Self {
|
||||||
Shared {
|
Shared {
|
||||||
allocator: allocator.clone(),
|
allocator: allocator.clone(),
|
||||||
|
@ -42,14 +42,17 @@ impl SemProc {
|
|||||||
self.arrays.insert(id, array);
|
self.arrays.insert(id, array);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a free ID
|
/// Get a free ID
|
||||||
fn get_free_id(&self) -> SemId {
|
fn get_free_id(&self) -> SemId {
|
||||||
(0..).find(|i| self.arrays.get(i).is_none()).unwrap()
|
(0..).find(|i| self.arrays.get(i).is_none()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an semaphore set by `id`
|
/// Get an semaphore set by `id`
|
||||||
pub fn get(&self, id: SemId) -> Option<Arc<SemArray>> {
|
pub fn get(&self, id: SemId) -> Option<Arc<SemArray>> {
|
||||||
self.arrays.get(&id).map(|a| a.clone())
|
self.arrays.get(&id).map(|a| a.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an undo operation
|
/// Add an undo operation
|
||||||
pub fn add_undo(&mut self, id: SemId, num: SemNum, op: SemOp) {
|
pub fn add_undo(&mut self, id: SemId, num: SemNum, op: SemOp) {
|
||||||
let old_val = *self.undos.get(&(id, num)).unwrap_or(&0);
|
let old_val = *self.undos.get(&(id, num)).unwrap_or(&0);
|
||||||
@ -95,12 +98,14 @@ impl ShmProc {
|
|||||||
self.shm_identifiers.insert(id, shm_identifier);
|
self.shm_identifiers.insert(id, shm_identifier);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a free ID
|
/// Get a free ID
|
||||||
fn get_free_id(&self) -> ShmId {
|
fn get_free_id(&self) -> ShmId {
|
||||||
(0..)
|
(0..)
|
||||||
.find(|i| self.shm_identifiers.get(i).is_none())
|
.find(|i| self.shm_identifiers.get(i).is_none())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an semaphore set by `id`
|
/// Get an semaphore set by `id`
|
||||||
pub fn get(&self, id: ShmId) -> Option<ShmIdentifier> {
|
pub fn get(&self, id: ShmId) -> Option<ShmIdentifier> {
|
||||||
self.shm_identifiers.get(&id).map(|a| a.clone())
|
self.shm_identifiers.get(&id).map(|a| a.clone())
|
||||||
@ -120,6 +125,7 @@ impl ShmProc {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pop Shared Area
|
/// Pop Shared Area
|
||||||
pub fn pop(&mut self, id: ShmId) {
|
pub fn pop(&mut self, id: ShmId) {
|
||||||
self.shm_identifiers.remove(&id);
|
self.shm_identifiers.remove(&id);
|
||||||
|
@ -363,11 +363,6 @@ impl Syscall<'_> {
|
|||||||
SYS_SHMAT => self.sys_shmat(args[0], args[1], args[2]),
|
SYS_SHMAT => self.sys_shmat(args[0], args[1], args[2]),
|
||||||
#[cfg(not(target_arch = "mips"))]
|
#[cfg(not(target_arch = "mips"))]
|
||||||
SYS_SHMDT => self.sys_shmdt(args[0], args[1], args[2]),
|
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
|
// system
|
||||||
SYS_GETPID => self.sys_getpid(),
|
SYS_GETPID => self.sys_getpid(),
|
||||||
SYS_GETTID => self.sys_gettid(),
|
SYS_GETTID => self.sys_gettid(),
|
||||||
|
Loading…
Reference in New Issue
Block a user