summaryrefslogtreecommitdiff
path: root/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-10-24 16:50:48 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-10-24 18:09:14 +0200
commitf16ad7f4cf4471edc4be46a6a3fb8799624fec73 (patch)
tree3a27fe7b79b5d25eebea4dfbaf18ef44a82bec4b /opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
parent8b53d07898841b328897c60427e6df9f8c71546e (diff)
bug(#4): Prevent scheduling to machines without processing units
This change prevents the currently available scheduler implementations from scheduling tasks to machines without processing units, since these machines cannot perform any work. Closes #4
Diffstat (limited to 'opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt')
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt6
1 files changed, 6 insertions, 0 deletions
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
index 761f14b1..b5016adb 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
@@ -81,6 +81,12 @@ open class Machine : Entity<Machine.State>, Process<Machine> {
val cpus = outgoingEdges.destinations<Cpu>("cpu")
val speed = cpus.fold(0, { acc, cpu -> acc + cpu.clockRate * cpu.cores })
+ // Halt the machine if it has not processing units (see bug #4)
+ if (cpus.isEmpty()) {
+ update(State(Status.HALT))
+ return
+ }
+
var task: Task = receiveTask()
update(State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0))