From 19ea47b3425f973c1ca92890cb8ee561b0ecab3d Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 10 Oct 2012 11:28:00 +0200 Subject: Fixed SI-6505. Respond to ask calls by immediate failure even after compiler shutdown. When the compiler is asked to shutdown, it may still have items on the working queue, and more can be added by clients in other thread that don't *know* the compiler is down yet. These requests were never serviced, leading to deadlocks or timeouts. review by @odersky, @hubertp --- .../scala/tools/nsc/interactive/CompilerControl.scala | 11 +++++++++++ src/compiler/scala/tools/nsc/util/InterruptReq.scala | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala index ae38a082ca..9b96608b69 100644 --- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala +++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala @@ -13,6 +13,7 @@ import scala.tools.nsc.util.FailedInterrupt import scala.tools.nsc.util.EmptyAction import scala.tools.nsc.util.WorkScheduler import scala.reflect.internal.util.{SourceFile, Position} +import scala.tools.nsc.util.InterruptReq /** Interface of interactive compiler to a client such as an IDE * The model the presentation compiler consists of the following parts: @@ -413,6 +414,16 @@ trait CompilerControl { self: Global => override def doQuickly[A](op: () => A): A = { throw new FailedInterrupt(new Exception("Posted a work item to a compiler that's shutting down")) } + + override def askDoQuickly[A](op: () => A): InterruptReq { type R = A } = { + val ir = new InterruptReq { + type R = A + val todo = () => throw new MissingResponse + } + ir.execute() + ir + } + } } diff --git a/src/compiler/scala/tools/nsc/util/InterruptReq.scala b/src/compiler/scala/tools/nsc/util/InterruptReq.scala index 816d16f767..b1b81d0952 100644 --- a/src/compiler/scala/tools/nsc/util/InterruptReq.scala +++ b/src/compiler/scala/tools/nsc/util/InterruptReq.scala @@ -47,7 +47,10 @@ abstract class InterruptReq { } def onComplete(k: Continuation) = synchronized { - waiting = k :: waiting + if (result.isDefined) + k(result.get) + else + waiting = k :: waiting } } -- cgit v1.2.3