From 1055e6a0ac82b7d10f988d84ef374081da7f1945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 20 Apr 2023 15:34:49 +0200 Subject: [PATCH] Fixed lock_release behaviour when multiple users of given lock --- src/kernel/thread_manager.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index 654f4e8..c6cd396 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -367,14 +367,14 @@ impl ThreadManager { 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); - 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()); } }