decrease some dependencies
This commit is contained in:
@@ -41,19 +41,19 @@ impl Semaphore {
|
||||
/// ### Parameters TODO Refaire
|
||||
/// - *current_thread* the current thread
|
||||
/// - *machine* the machine where the threads are executed
|
||||
pub fn p(&mut self, system: &mut System) {
|
||||
let old_status = system.get_machine().interrupt.set_status(InterruptOff);
|
||||
pub fn p(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||
self.counter -= 1;
|
||||
if self.counter < 0 {
|
||||
match system.get_thread_manager().get_g_current_thread() {
|
||||
match thread_manager.get_g_current_thread() {
|
||||
Some(thread) => {
|
||||
self.waiting_queue.push(Rc::clone(thread));
|
||||
system.get_thread_manager().thread_sleep(system, Rc::clone(thread));
|
||||
thread_manager.thread_sleep(machine, Rc::clone(thread));
|
||||
},
|
||||
None => unreachable!("Current thread should not be None")
|
||||
}
|
||||
}
|
||||
system.get_machine().interrupt.set_status(old_status);
|
||||
machine.interrupt.set_status(old_status);
|
||||
}
|
||||
|
||||
/// Increment semaphore value, waking up a waiting thread if any.
|
||||
@@ -112,30 +112,31 @@ impl Lock {
|
||||
/// ### Parameters
|
||||
/// - **current_thread** the current thread
|
||||
/// - **machine** the machine where the threads are executed
|
||||
pub fn acquire(&mut self, system: &mut System) {
|
||||
let old_status = system.get_machine().interrupt.set_status(InterruptOff);
|
||||
pub fn acquire(&mut self, thread_manager: &mut ThreadManager, machine: &mut Machine) {
|
||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||
|
||||
if self.free {
|
||||
self.free = false;
|
||||
self.owner = Option::Some(match system.get_thread_manager().get_g_current_thread() {
|
||||
self.owner = Option::Some(match thread_manager.get_g_current_thread() {
|
||||
Some(th) => {
|
||||
Rc::clone(th)
|
||||
},
|
||||
None => unreachable!()
|
||||
});
|
||||
} else {
|
||||
let t = system.get_thread_manager().get_g_current_thread();
|
||||
let t = thread_manager.get_g_current_thread();
|
||||
match t {
|
||||
Some(x) => {
|
||||
let x = Rc::clone(x);
|
||||
self.waiting_queue.push(Rc::clone(&x));
|
||||
system.thread_sleep(Rc::clone(&x));
|
||||
|
||||
thread_manager.thread_sleep(machine, Rc::clone(&x));
|
||||
},
|
||||
None => unreachable!("Current thread should not be None")
|
||||
}
|
||||
}
|
||||
|
||||
system.get_machine().interrupt.set_status(old_status);
|
||||
machine.interrupt.set_status(old_status);
|
||||
}
|
||||
|
||||
/// Wake up a waiter if necessary, or release it if no thread is waiting.
|
||||
@@ -266,10 +267,10 @@ mod test {
|
||||
fn test_semaphore_single() {
|
||||
// Init
|
||||
let system = init_system!();
|
||||
let mut semaphore = Semaphore::new(1, Rc::clone(&system.borrow_mut().get_thread_manager()));
|
||||
let mut semaphore = Semaphore::new(1);
|
||||
let thread = Rc::new(RefCell::new(Thread::new("test_semaphore")));
|
||||
// P
|
||||
semaphore.p(thread, Rc::clone(&system));
|
||||
semaphore.p(system, thread);
|
||||
assert_eq!(semaphore.counter, 0);
|
||||
assert!(semaphore.waiting_queue.is_empty());
|
||||
// V
|
||||
|
||||
Reference in New Issue
Block a user