diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-10 15:01:13 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-10 15:01:13 +0000 |
commit | 28e6744e2305f523d16458a9d8c748903e33aca5 (patch) | |
tree | 23ecfffb8c26dcb509e1bff21580b7dbf9403af3 /src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala | |
parent | 68808e80c4574e419a440c31d24ad206870e28b3 (diff) | |
download | scala-28e6744e2305f523d16458a9d8c748903e33aca5.tar.gz scala-28e6744e2305f523d16458a9d8c748903e33aca5.tar.bz2 scala-28e6744e2305f523d16458a9d8c748903e33aca5.zip |
A somewhat more realistic attempt to fix the bu...
A somewhat more realistic attempt to fix the build, no review. This
introduces a repl command line option -Yrepl-sync to inhibit the
asynchronous path which makes repl startup seem so snappy. And then it
uses it in the repl tests.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala b/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala index a8fb619f97..f2171ad732 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala @@ -61,6 +61,10 @@ trait ILoopInit { } private val initLock = new java.util.concurrent.locks.ReentrantLock() + private val initCompilerCondition = initLock.newCondition() // signal the compiler is initialized + private val initLoopCondition = initLock.newCondition() // signal the whole repl is initialized + private val initStart = System.nanoTime + private def withLock[T](body: => T): T = { initLock.lock() try body @@ -68,41 +72,45 @@ trait ILoopInit { } // a condition used to ensure serial access to the compiler. @volatile private var initIsComplete = false - private val initCompilerCondition = initLock.newCondition() // signal the compiler is initialized - private val initLoopCondition = initLock.newCondition() // signal the whole repl is initialized - private val initStart = System.nanoTime private def elapsed() = "%.3f".format((System.nanoTime - initStart).toDouble / 1000000000L) - // Receives a single message once the interpreter is initialized. - private val initializedReactor = io.spawn { - withLock(initCompilerCondition.await()) - asyncMessage("[info] compiler init time: " + elapsed() + " s.") - postInitialization() - } - // the method to be called when the interpreter is initialized. // Very important this method does nothing synchronous (i.e. do // not try to use the interpreter) because until it returns, the // repl's lazy val `global` is still locked. protected def initializedCallback() = withLock(initCompilerCondition.signal()) + // Spins off a thread which awaits a single message once the interpreter + // has been initialized. + protected def createAsyncListener() = { + io.spawn { + withLock(initCompilerCondition.await()) + asyncMessage("[info] compiler init time: " + elapsed() + " s.") + postInitialization() + } + } + // called from main repl loop protected def awaitInitialized() { if (!initIsComplete) withLock { while (!initIsComplete) initLoopCondition.await() } } + protected def postInitThunks = List[Option[() => Unit]]( + Some(intp.setContextClassLoader _), + if (isReplPower) Some(() => enablePowerMode(true)) else None, + // do this last to avoid annoying uninterruptible startups + Some(installSigIntHandler _) + ).flatten // called once after init condition is signalled protected def postInitialization() { - addThunk(intp.setContextClassLoader()) - if (isReplPower) - addThunk(enablePowerMode(true)) - // do this last to avoid annoying uninterruptible startups - addThunk(installSigIntHandler()) - + postInitThunks foreach (f => addThunk(f())) runThunks() initIsComplete = true - asyncMessage("[info] total init time: " + elapsed() + " s.") - withLock(initLoopCondition.signal()) + + if (isAsync) { + asyncMessage("[info] total init time: " + elapsed() + " s.") + withLock(initLoopCondition.signal()) + } } // code to be executed only after the interpreter is initialized // and the lazy val `global` can be accessed without risk of deadlock. |