Fixed lock_release behaviour when multiple users of given lock

This commit is contained in:
François Autin 2023-04-20 15:34:49 +02:00
parent f6195a9da0
commit 31f1e760e9

View File

@ -367,14 +367,14 @@ impl ThreadManager {
if let Some(lock_owner) = &lock.owner {
if Rc::ptr_eq(&current_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);
lock.free = true;
} else {
lock.free = true;
lock.owner = None;
}
}}
}
};
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: ");
{
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
assert!(lock.waiting_queue.is_empty());
assert_eq!(lock.owner, None);
assert!(lock.free);
assert!(lock.waiting_queue.is_empty());
}
}