From 7d62262984d0cf10e7990b47975e6a300ebca4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Jun 2014 21:51:25 +0200 Subject: [PATCH] Fixed pseudo-racing condition in package relay of switches and co. that could increase the time it took to resend a packet. Closes #327. --- .../scala/li/cil/oc/common/tileentity/traits/Hub.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala index 9a1d0ce98..8abd60395 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala @@ -39,14 +39,19 @@ trait Hub extends traits.Environment with SidedEnvironment { else if (queue.nonEmpty) queue.synchronized { val (sourceSide, packet) = queue.dequeue() relayPacket(sourceSide, packet) - relayCooldown = relayDelay + if (queue.nonEmpty) { + relayCooldown = relayDelay + } + else { + relayCooldown = -1 + } } } protected def tryEnqueuePacket(sourceSide: ForgeDirection, packet: Packet) = queue.synchronized { if (packet.ttl > 0 && queue.size < maxQueueSize) { queue += sourceSide -> packet.hop() - if (relayCooldown <= 0) { + if (relayCooldown < 0) { relayCooldown = relayDelay } true