diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-09-05 23:33:35 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-09-05 23:33:35 +0200 |
| commit | 89d38062bf439c7cf6f731ab6305ccc0e118d9e1 (patch) | |
| tree | f834c0d101b5981c87504c8175a657e756b51730 /opendc-core/src | |
| parent | ba58a697c9a8817e2c0a91e4af385d743ed209c5 (diff) | |
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.
Diffstat (limited to 'opendc-core/src')
4 files changed, 11 insertions, 11 deletions
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<out T: Component<*>>: 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<out T: Component<*>>: 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<Unit> { * * @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<Unit> { * * @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<out T: Entity<*>>: Component<T> { } /** - * 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 <reified T> 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 <reified T> 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<Machine.State>, Kernel<EntityContext<Machine>> { val task: Task val delay = Random().nextInt(1000) - sleep(delay) + wait(delay) loop@while (true) { val msg = receive() |
