summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt8
1 files changed, 6 insertions, 2 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
index b2a01804..b0688f99 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
@@ -3,6 +3,7 @@ package com.atlarge.opendc.compute.core.image
import com.atlarge.odcsim.simulationContext
import com.atlarge.opendc.compute.core.execution.ServerContext
import com.atlarge.opendc.core.resource.TagContainer
+import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import java.util.UUID
@@ -19,8 +20,11 @@ class VmImage(
) : Image {
override suspend fun invoke(ctx: ServerContext) {
+ val clock = simulationContext.clock
+ val job = coroutineContext[Job]!!
+
for (fragment in flopsHistory) {
- coroutineContext.ensureActive()
+ job.ensureActive()
if (fragment.flops == 0L) {
delay(fragment.duration)
@@ -29,7 +33,7 @@ class VmImage(
val burst = LongArray(cores) { fragment.flops / cores }
val usage = DoubleArray(cores) { fragment.usage / cores }
- ctx.run(burst, usage, simulationContext.clock.millis() + fragment.duration)
+ ctx.run(burst, usage, clock.millis() + fragment.duration)
}
}
}