From 823bb2d217e6b35b1811b5f52016d8d9de09435d Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 6 Sep 2017 14:53:01 +0200 Subject: Implement time jumps to next event This change implements a time jump to the next event in the queue if there are no events scheduled for the current tick. --- .../kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt | 10 ++++++---- opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'opendc-core') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt index 6b7407e5..764134e5 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt @@ -121,13 +121,15 @@ class OmegaSimulator(override val topology: Topology): Simulator, Iterator while (true) { val (tick, block) = clock.queue.peek() ?: return - if (tick > clock.tick) + if (tick > clock.tick) { // Tick has yet to occur + // Jump in time to next event + clock.tick = tick - 1 break - else if (tick < clock.tick) + } else if (tick < clock.tick) { // Tick has already occurred - logger.warn {"tick was not handled correctly"} - + logger.warn { "tick was not handled correctly" } + } clock.queue.poll() block() } diff --git a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt index 7d3c317e..50e22734 100644 --- a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt @@ -37,7 +37,7 @@ internal class SmokeTest { val builder = AdjacencyListTopologyBuilder() val topology = builder.build().apply { val rack = node(Rack()) - val n = 1000000 + val n = 100 // Create n machines in the rack repeat(n) { val machine = node(Machine()) -- cgit v1.2.3