summaryrefslogtreecommitdiff
path: root/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt')
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt15
1 files changed, 10 insertions, 5 deletions
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt
index cc196a00..5382e48b 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt
@@ -54,19 +54,24 @@ class FifoScheduler : Scheduler {
return
}
+ val iterator = queue.iterator()
+
machines
- .filter { it.state.status == Machine.Status.IDLE }
- .forEach {
- while (queue.isNotEmpty()) {
- val task = queue.poll()
+ .forEach { machine ->
+ while (iterator.hasNext()) {
+ val task = iterator.next()
// TODO What to do with tasks that are not ready yet to be processed
if (!task.isReady()) {
+ iterator.remove()
submit(task)
continue
+ } else if (task.finished) {
+ iterator.remove()
+ continue
}
- it.send(task)
+ machine.send(task)
break
}
}