diff --git a/src/kernel/synch.rs b/src/kernel/synch.rs index 3828d3a..15996ac 100644 --- a/src/kernel/synch.rs +++ b/src/kernel/synch.rs @@ -24,6 +24,11 @@ pub struct Semaphore { impl Semaphore { + /// Initializes a semaphore, so that it can be used for synchronization. + /// + /// ### Parameters + /// - *counter* initial value of counter + /// - *thread_manager* Thread manager which managing threads pub fn new(counter: i32, thread_manager: Rc>) -> Semaphore{ Semaphore { counter, waiting_queue: List::new(), thread_manager} } @@ -153,7 +158,10 @@ impl Lock { } pub fn held_by_current_thread(&mut self, current_thread: Rc>) -> bool { - Rc::ptr_eq(&self.owner, ¤t_thread) + match &self.owner { + Some(x) => Rc::ptr_eq(&x, ¤t_thread), + None => false + } } }