Try to fix double free
This commit is contained in:
parent
02cdb5239b
commit
28cd0a9f6e
@ -355,29 +355,30 @@ impl ThreadManager {
|
|||||||
|
|
||||||
/// Wake up a waiter if necessary, or release it if no thread is waiting.
|
/// 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> {
|
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() {
|
let current_thread = match self.get_g_current_thread() {
|
||||||
Some(thread) => Rc::clone(thread),
|
Some(thread) => Rc::clone(thread),
|
||||||
None => Err(String::from("lock_release error: current_thread should not be None."))?
|
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,
|
Some(lock) => lock,
|
||||||
None => Err(String::from("lock_release error: cannot find 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 let Some(lock_owner) = &lock.owner {
|
||||||
if Rc::ptr_eq(¤t_thread, lock_owner) {
|
if current_thread.eq(lock_owner) { // is_held_by_current_thread
|
||||||
if let Some(thread) = lock.waiting_queue.pop() {
|
match lock.waiting_queue.pop() {
|
||||||
if !lock.waiting_queue.is_empty() {
|
Some(th) => {
|
||||||
let clone = Rc::clone(&thread);
|
lock.owner = Some(Rc::clone(&th));
|
||||||
lock.owner = Some(thread);
|
self.ready_to_run(Rc::clone(&th));
|
||||||
self.ready_to_run(clone);
|
},
|
||||||
} else {
|
None => {
|
||||||
lock.free = true;
|
lock.free = true;
|
||||||
lock.owner = None;
|
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);
|
machine.interrupt.set_status(old_status);
|
||||||
Ok(MachineOk::Ok)
|
Ok(MachineOk::Ok)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user