summaryrefslogtreecommitdiff
path: root/opendc-experiments/opendc-experiments-tf20/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-28 11:58:19 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-03 17:17:37 +0200
commit02fa44c0b116ff51c4cbe2876d8b2a225ed68553 (patch)
tree38562ef2e6f3cde4e46ad5eb32d7573cebaabef6 /opendc-experiments/opendc-experiments-tf20/src
parentd575bed5418be222e1d3ad39af862e2390596d61 (diff)
refactor(simulator): Add support for pushing flow from context
This change adds a new method to `SimResourceContext` called `push` which allows users to change the requested flow rate directly without having to interrupt the consumer.
Diffstat (limited to 'opendc-experiments/opendc-experiments-tf20/src')
-rw-r--r--opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt11
1 files changed, 7 insertions, 4 deletions
diff --git a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
index bfc5fc6f..1fbd3b6a 100644
--- a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
+++ b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
@@ -128,7 +128,7 @@ public class SimTFDevice(
}
}
- override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): Long {
val consumedWork = ctx.speed * delta / 1000.0
val activeWork = activeWork
@@ -137,7 +137,8 @@ public class SimTFDevice(
this.activeWork = null
} else {
val duration = (activeWork.flops / ctx.capacity * 1000).roundToLong()
- return SimResourceCommand.Consume(ctx.capacity, duration)
+ ctx.push(ctx.capacity)
+ return duration
}
}
@@ -146,9 +147,11 @@ public class SimTFDevice(
return if (head != null) {
this.activeWork = head
val duration = (head.flops / ctx.capacity * 1000).roundToLong()
- SimResourceCommand.Consume(ctx.capacity, duration)
+ ctx.push(ctx.capacity)
+ duration
} else {
- SimResourceCommand.Consume(0.0)
+ ctx.push(0.0)
+ Long.MAX_VALUE
}
}