balls
This commit is contained in:
51
src/main.rs
51
src/main.rs
@@ -134,38 +134,33 @@ pub fn round_robin(procs: Vec<Process>, q: i32) -> Vec<Process> {
|
|||||||
let mut current_time = 0;
|
let mut current_time = 0;
|
||||||
let mut in_cpu: Vec<Process> = vec![];
|
let mut in_cpu: Vec<Process> = vec![];
|
||||||
let mut done: Vec<Process> = vec![];
|
let mut done: Vec<Process> = vec![];
|
||||||
while !buffer.is_empty() || !in_cpu.is_empty() {
|
loop {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
if !buffer.is_empty() {
|
for proc in buffer.to_owned() {
|
||||||
for proc in buffer.to_owned() {
|
if proc.arrival <= current_time {
|
||||||
if buffer.is_empty() {
|
in_cpu.push(proc);
|
||||||
continue;
|
buffer.remove(counter);
|
||||||
}
|
|
||||||
if proc.arrival <= current_time {
|
|
||||||
in_cpu.push(proc);
|
|
||||||
buffer.remove(counter);
|
|
||||||
}
|
|
||||||
counter += 1;
|
|
||||||
}
|
}
|
||||||
|
counter += 1;
|
||||||
}
|
}
|
||||||
if !in_cpu.is_empty() {
|
match in_cpu.to_owned().first_mut() {
|
||||||
let mut current_proc = in_cpu.remove(0);
|
Some(proc) => {
|
||||||
if current_proc.remaining < q {
|
(proc.remaining, current_time) = proc.quan_zap(q, current_time);
|
||||||
current_time += current_proc.remaining;
|
if proc.remaining == 0 {
|
||||||
} else {
|
proc.completion_time = current_time;
|
||||||
current_time += q;
|
proc.turnaround = proc.calc_turn();
|
||||||
|
proc.waiting = proc.calc_wait();
|
||||||
|
done.push(proc.to_owned());
|
||||||
|
} else {
|
||||||
|
in_cpu.push(proc.to_owned())
|
||||||
|
}
|
||||||
|
in_cpu.remove(0);
|
||||||
}
|
}
|
||||||
current_proc.remaining = current_proc.robin_zap(q);
|
None => current_time += 1,
|
||||||
if current_proc.remaining == 0 {
|
}
|
||||||
current_proc.completion_time = current_time;
|
|
||||||
current_proc.turnaround = current_proc.calc_turn();
|
if in_cpu.is_empty() && buffer.is_empty() {
|
||||||
current_proc.waiting = current_proc.calc_wait();
|
break;
|
||||||
done.push(current_proc);
|
|
||||||
} else {
|
|
||||||
in_cpu.push(current_proc);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
current_time += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user