From 89d38062bf439c7cf6f731ab6305ccc0e118d9e1 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 5 Sep 2017 23:33:35 +0200 Subject: Rename sleep() to wait() This change renames the sleep(n) method to wait(n) to make clear that the method will not cause the thread to sleep, but instead suspends the kernel and allows other kernels to still run during the waiting period. --- .../src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt | 4 ++-- .../src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt | 4 ++-- .../src/main/kotlin/nl/atlarge/opendc/topology/Node.kt | 12 ++++++------ .../kotlin/nl/atlarge/opendc/topology/machine/Machine.kt | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'opendc-core/src') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt index fb8c2044..37d21d60 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt @@ -55,7 +55,7 @@ interface Context>: Readable { * Suspend the simulation kernel until the next tick occurs in the simulation. */ suspend fun tick(): Boolean { - sleep(1) + wait(1) return true } @@ -64,5 +64,5 @@ interface Context>: Readable { * * @param n The amount of ticks to suspend the simulation kernel. */ - suspend fun sleep(n: Int) + suspend fun wait(n: Int) } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt index dfe41295..c173418d 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt @@ -180,7 +180,7 @@ class Simulator(val topology: Topology): Iterator { * * @param n The amount of ticks to suspend the simulation kernel. */ - suspend override fun sleep(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } + suspend override fun wait(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } } /** @@ -220,7 +220,7 @@ class Simulator(val topology: Topology): Iterator { * * @param n The amount of ticks to suspend the simulation kernel. */ - suspend override fun sleep(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } + suspend override fun wait(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } } /** diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt index 39d1a804..c21fd088 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt @@ -60,22 +60,22 @@ interface Node>: Component { } /** - * Return the set of ingoing edges of this node with the given tag. + * Return the set of entities that are connected inwards to this node with the given tag. * * @param tag The tag of the edges to get. * @param T The shape of the label of these edges. - * @return All edges whose destination is this node and have the given tag. + * @return The entities of all edges whose destination is this node and have the given tag. */ inline fun Node<*>.ingoing(tag: String) = - ingoingEdges().filter { it.tag == tag }.map { it.label as T }.toSet() + ingoingEdges().filter { it.tag == tag }.map { it.to.entity as T }.toSet() /** - * Return the set of outgoing edges of this node with the given tag. + * Return the set of entities that are connected outwards to this node with the given tag. * * @param tag The tag of the edges to get. * @param T The shape of the label of these edges. - * @return All edges whose source is this node and have the given tag. + * @return The entities of all edges whose source is this node and have the given tag. */ inline fun Node<*>.outgoing(tag: String) = - outgoingEdges().filter { it.tag == tag }.map { it.label as T }.toSet() + outgoingEdges().filter { it.tag == tag }.map { it.to.entity as T }.toSet() diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt index f310e103..049f82b8 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt @@ -66,7 +66,7 @@ class Machine: Entity, Kernel> { val task: Task val delay = Random().nextInt(1000) - sleep(delay) + wait(delay) loop@while (true) { val msg = receive() -- cgit v1.2.3