diff --git a/src/kernel/synch.rs b/src/kernel/synch.rs index d2cdd99..a7a5be2 100644 --- a/src/kernel/synch.rs +++ b/src/kernel/synch.rs @@ -10,15 +10,15 @@ use super::scheduler::Scheduler; use super::thread_manager::ThreadManager; /// Structure of a Semaphore used for synchronisation -pub struct Semaphore<'t> { +pub struct Semaphore { counter:i32, waiting_queue:List>>, - thread_manager: Rc>> // On s'assure que le tm vit plus longtemps que les semaphore avec le lifetime + thread_manager: Rc> // On s'assure que le tm vit plus longtemps que les semaphore avec le lifetime } -impl<'t> Semaphore<'_> { +impl<'t> Semaphore { /// Decrement the value, and wait if it becomes < 0. Checking the /// value and decrementing must be done atomically, so we @@ -63,16 +63,16 @@ impl<'t> Semaphore<'_> { /// Lock used for synchronisation, can be interpreted has a Semaphore with a /// counter of 1 /// It's used for critical parts -pub struct Lock<'t>{ +pub struct Lock{ owner: Rc>, waiting_queue:List>>, - thread_manager: Rc>>, + thread_manager: Rc>, free: bool } -impl<'t> Lock<'_> { +impl<'t> Lock { /// Wait until the lock become free. Checking the /// state of the lock (free or busy) and modify it must be done @@ -111,7 +111,7 @@ impl<'t> Lock<'_> { pub fn release(&mut self, machine: &mut Machine, scheduler: &mut Scheduler, current_thread: Rc>) { let old_status = machine.interrupt.set_status(InterruptOff); - if self.is_held_by_current_thread(current_thread) { + if self.held_by_current_thread(current_thread) { if self.waiting_queue.peek() != None { self.owner = self.waiting_queue.pop().unwrap(); scheduler.ready_to_run(Rc::clone(&self.owner)); @@ -123,20 +123,20 @@ impl<'t> Lock<'_> { machine.interrupt.set_status(old_status); } - pub fn is_held_by_current_thread(&mut self, current_thread: Rc>) -> bool { + pub fn held_by_current_thread(&mut self, current_thread: Rc>) -> bool { Rc::ptr_eq(&self.owner, ¤t_thread) } } /// Structure of a condition used for synchronisation -pub struct Condition<'t>{ +pub struct Condition{ waiting_queue:List>>, - thread_manager: Rc>>, + thread_manager: Rc>, } -impl<'t> Condition<'_> { +impl<'t> Condition { /// Block the calling thread (put it in the wait queue). /// This operation must be atomic, so we need to disable interrupts.