Try to fix double free
This commit is contained in:
parent
9dec9b041a
commit
7b7d48c775
@ -367,29 +367,30 @@ impl ThreadManager {
|
||||
|
||||
/// Wake up a waiter if necessary, or release it if no thread is waiting.
|
||||
pub fn lock_release(&mut self, id: i32, machine: &mut Machine) -> Result<MachineOk, MachineError> {
|
||||
let old_status = machine.interrupt.set_status(InterruptStatus::InterruptOff);
|
||||
let current_thread = match self.get_g_current_thread() {
|
||||
Some(thread) => Rc::clone(thread),
|
||||
None => Err(String::from("lock_release error: current_thread should not be None."))?
|
||||
};
|
||||
let mut lock = match self.get_obj_addrs().search_lock(id).cloned() {
|
||||
let mut lock = match self.get_obj_addrs().search_lock(id) {
|
||||
Some(lock) => lock,
|
||||
None => Err(String::from("lock_release error: cannot find lock."))?
|
||||
};
|
||||
let old_status = machine.interrupt.set_status(InterruptStatus::InterruptOff);
|
||||
if let Some(lock_owner) = &lock.owner {
|
||||
if Rc::ptr_eq(¤t_thread, lock_owner) {
|
||||
if let Some(thread) = lock.waiting_queue.pop() {
|
||||
if !lock.waiting_queue.is_empty() {
|
||||
let clone = Rc::clone(&thread);
|
||||
lock.owner = Some(thread);
|
||||
self.ready_to_run(clone);
|
||||
} else {
|
||||
if current_thread.eq(lock_owner) { // is_held_by_current_thread
|
||||
match lock.waiting_queue.pop() {
|
||||
Some(th) => {
|
||||
lock.owner = Some(Rc::clone(&th));
|
||||
self.ready_to_run(Rc::clone(&th));
|
||||
},
|
||||
None => {
|
||||
lock.free = true;
|
||||
lock.owner = None;
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
self.get_obj_addrs().update_lock(id, lock);
|
||||
// self.get_obj_addrs().update_lock(id, lock);
|
||||
machine.interrupt.set_status(old_status);
|
||||
Ok(MachineOk::Ok)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user