Merge branch 'thread_scheduler' of gitlab.istic.univ-rennes1.fr:simpleos/burritos into thread_scheduler
This commit is contained in:
commit
6edb88f337
@ -67,8 +67,9 @@ impl Semaphore {
|
|||||||
pub fn v(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager){
|
pub fn v(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager){
|
||||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||||
self.counter += 1;
|
self.counter += 1;
|
||||||
if self.waiting_queue.peek() != None {
|
match self.waiting_queue.pop() {
|
||||||
thread_manager.ready_to_run(self.waiting_queue.pop().unwrap());
|
Some(thread) => thread_manager.ready_to_run(thread),
|
||||||
|
None => ()
|
||||||
}
|
}
|
||||||
machine.interrupt.set_status(old_status);
|
machine.interrupt.set_status(old_status);
|
||||||
}
|
}
|
||||||
@ -149,15 +150,18 @@ impl Lock {
|
|||||||
match thread_manager.get_g_current_thread() {
|
match thread_manager.get_g_current_thread() {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
if self.held_by_current_thread(thread_manager) {
|
if self.held_by_current_thread(thread_manager) {
|
||||||
if self.waiting_queue.peek().is_none() {
|
match self.waiting_queue.pop() {
|
||||||
self.owner = Some(self.waiting_queue.pop().unwrap());
|
Some(thread) => {
|
||||||
match &self.owner {
|
self.owner = Some(thread);
|
||||||
Some(x) => thread_manager.ready_to_run(Rc::clone(x)),
|
match &self.owner {
|
||||||
None => ()
|
Some(x) => thread_manager.ready_to_run(Rc::clone(&x)),
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
self.free = true;
|
||||||
|
self.owner = None;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.free = true;
|
|
||||||
self.owner = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,8 +233,9 @@ impl Condition {
|
|||||||
pub fn signal(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
pub fn signal(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
||||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||||
|
|
||||||
if self.waiting_queue.peek().is_none() {
|
match self.waiting_queue.pop() {
|
||||||
thread_manager.ready_to_run(self.waiting_queue.pop().unwrap());
|
Some(thread) => thread_manager.ready_to_run(thread),
|
||||||
|
None => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
machine.interrupt.set_status(old_status);
|
machine.interrupt.set_status(old_status);
|
||||||
@ -246,8 +251,9 @@ impl Condition {
|
|||||||
pub fn broadcast(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
pub fn broadcast(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
||||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||||
|
|
||||||
while self.waiting_queue.peek().is_none() {
|
match self.waiting_queue.pop() {
|
||||||
thread_manager.ready_to_run(self.waiting_queue.pop().unwrap());
|
Some(thread) => thread_manager.ready_to_run(thread),
|
||||||
|
None => ()
|
||||||
}
|
}
|
||||||
machine.interrupt.set_status(old_status);
|
machine.interrupt.set_status(old_status);
|
||||||
|
|
||||||
|
@ -189,4 +189,11 @@ impl ThreadManager {
|
|||||||
self.g_thread_to_be_destroyed = thread
|
self.g_thread_to_be_destroyed = thread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user