Fixed lock_release behaviour when multiple users of given lock
This commit is contained in:
parent
f6195a9da0
commit
31f1e760e9
@ -367,14 +367,14 @@ impl ThreadManager {
|
|||||||
if let Some(lock_owner) = &lock.owner {
|
if let Some(lock_owner) = &lock.owner {
|
||||||
if Rc::ptr_eq(¤t_thread, lock_owner) {
|
if Rc::ptr_eq(¤t_thread, lock_owner) {
|
||||||
if let Some(thread) = lock.waiting_queue.pop() {
|
if let Some(thread) = lock.waiting_queue.pop() {
|
||||||
|
if !lock.waiting_queue.is_empty() {
|
||||||
let clone = Rc::clone(&thread);
|
let clone = Rc::clone(&thread);
|
||||||
lock.owner = Some(thread);
|
lock.owner = Some(thread);
|
||||||
self.ready_to_run(clone);
|
self.ready_to_run(clone);
|
||||||
lock.free = true;
|
|
||||||
} else {
|
} else {
|
||||||
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);
|
||||||
@ -514,9 +514,9 @@ mod test {
|
|||||||
thread_manager.lock_release(lock_id, &mut machine).expect("lock release return an error at second iteration: ");
|
thread_manager.lock_release(lock_id, &mut machine).expect("lock release return an error at second iteration: ");
|
||||||
{
|
{
|
||||||
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
||||||
|
assert!(lock.waiting_queue.is_empty());
|
||||||
assert_eq!(lock.owner, None);
|
assert_eq!(lock.owner, None);
|
||||||
assert!(lock.free);
|
assert!(lock.free);
|
||||||
assert!(lock.waiting_queue.is_empty());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user