summaryrefslogtreecommitdiff
path: root/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler')
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/FifoScheduler.kt15
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/SrtfScheduler.kt5
2 files changed, 12 insertions, 8 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
}
}
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/SrtfScheduler.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/SrtfScheduler.kt
index ce80ddc3..0e94f81a 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/SrtfScheduler.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/scheduler/SrtfScheduler.kt
@@ -57,8 +57,7 @@ class SrtfScheduler : Scheduler {
val iterator = tasks.sortedBy { it.remaining }.iterator()
machines
- .filter { it.state.status == Machine.Status.IDLE }
- .forEach {
+ .forEach { machine ->
while (iterator.hasNext()) {
val task = iterator.next()
@@ -71,7 +70,7 @@ class SrtfScheduler : Scheduler {
continue
}
- it.send(task)
+ machine.send(task)
break
}
}