loader now return better understanable errors, fix when compiler when to use bss section, add join exception, fix get_string_param, add support for thread in obbAddr, add a test
This commit is contained in:
@ -2,9 +2,9 @@
|
||||
//! their references. The ObjAddr struct
|
||||
//! allows to maintain this data structure.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, cell::RefCell, rc::Rc};
|
||||
|
||||
use crate::kernel::synch::{ Semaphore, Lock };
|
||||
use crate::kernel::{synch::{ Semaphore, Lock }, thread::Thread};
|
||||
|
||||
/// Brief Definition of object identifiers:
|
||||
///
|
||||
@ -19,7 +19,8 @@ use crate::kernel::synch::{ Semaphore, Lock };
|
||||
pub struct ObjAddr {
|
||||
last_id: i32,
|
||||
semaphores: HashMap<i32, Semaphore>,
|
||||
locks: HashMap<i32, Lock>
|
||||
locks: HashMap<i32, Lock>,
|
||||
threads: HashMap<i32, Rc<RefCell<Thread>>>,
|
||||
}
|
||||
|
||||
impl ObjAddr {
|
||||
@ -29,7 +30,8 @@ impl ObjAddr {
|
||||
Self {
|
||||
last_id: 3,
|
||||
semaphores: HashMap::<i32, Semaphore>::new(),
|
||||
locks: HashMap::<i32, Lock>::new()
|
||||
locks: HashMap::<i32, Lock>::new(),
|
||||
threads: HashMap::<i32, Rc<RefCell<Thread>>>::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +49,13 @@ impl ObjAddr {
|
||||
self.last_id
|
||||
}
|
||||
|
||||
/// Adds the **obj** Lock to self
|
||||
pub fn add_thread(&mut self, obj: Rc<RefCell<Thread>>) -> i32 {
|
||||
self.last_id +=1;
|
||||
self.threads.insert(self.last_id, obj);
|
||||
self.last_id
|
||||
}
|
||||
|
||||
/// Searches for a semaphore of id **id** in self
|
||||
pub fn search_semaphore(&mut self, id: i32) -> Option<&mut Semaphore> {
|
||||
self.semaphores.get_mut(&id)
|
||||
@ -57,6 +66,11 @@ impl ObjAddr {
|
||||
self.locks.get_mut(&id)
|
||||
}
|
||||
|
||||
/// Searches for a lock of id **id** in self
|
||||
pub fn search_thread(&mut self, id: i32) -> Option<&Rc<RefCell<Thread>>> {
|
||||
self.threads.get(&id)
|
||||
}
|
||||
|
||||
/// Removes the object of id **id** from self if it exists
|
||||
pub fn remove_semaphore(&mut self, id: i32) -> Option<Semaphore> {
|
||||
self.semaphores.remove(&id)
|
||||
@ -67,5 +81,10 @@ impl ObjAddr {
|
||||
self.locks.remove(&id)
|
||||
}
|
||||
|
||||
/// Remove the object of id **id** from self if it exists
|
||||
pub fn remove_thread(&mut self, id: i32) -> Option<Rc<RefCell<Thread>>> {
|
||||
self.threads.remove(&id)
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user