From 39cfa9724c71796f2c16aa1ed90fbd4425540eef Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 20 Sep 2017 00:59:54 +0200 Subject: Add support for timeouts on receive calls This change allows processes to set a timeout when waiting for a message to arrive. --- .../src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'opendc-stdlib/src/main/kotlin') 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 0884a725..163f280f 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 @@ -28,6 +28,7 @@ import nl.atlarge.opendc.extension.destinations import nl.atlarge.opendc.workload.Task import nl.atlarge.opendc.kernel.Context import nl.atlarge.opendc.kernel.Process +import nl.atlarge.opendc.kernel.time.Duration import nl.atlarge.opendc.topology.Entity /** @@ -60,6 +61,7 @@ class Machine : Entity, Process { override suspend fun Context.run() { update(State(Status.IDLE)) + val interval: Duration = 10 val cpus = outgoingEdges.destinations("cpu") val speed = cpus.fold(0, { acc, (speed, cores) -> acc + speed * cores }).toLong() var task: Task? = null @@ -74,7 +76,7 @@ class Machine : Entity, Process { } } - val msg = receive() + val msg = receive(interval) if (msg is Task) { task = msg update(State(Status.RUNNING, task)) -- cgit v1.2.3