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 c278236d81
commit 1055e6a0ac
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -367,14 +367,14 @@ impl ThreadManager {
if let Some(lock_owner) = &lock.owner { if let Some(lock_owner) = &lock.owner {
if Rc::ptr_eq(&current_thread, lock_owner) { if Rc::ptr_eq(&current_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());
} }
} }