From 22b60f2f2b6dbacbd528d10cb18da8e5afe750da Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 22 May 2009 15:13:22 +0000 Subject: some documentation; statistics wrt implicits; n... some documentation; statistics wrt implicits; new presentation compiler --- .../scala/tools/nsc/util/WorkScheduler.scala | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/compiler/scala/tools/nsc/util/WorkScheduler.scala (limited to 'src/compiler/scala/tools/nsc/util/WorkScheduler.scala') diff --git a/src/compiler/scala/tools/nsc/util/WorkScheduler.scala b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala new file mode 100644 index 0000000000..7bcd3b7a8e --- /dev/null +++ b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala @@ -0,0 +1,43 @@ +package scala.tools.nsc.util + +import scala.collection.mutable.Queue + +class WorkScheduler { + + type Action = () => Unit + + private var todo = new Queue[Action] + + /** Called from server */ + def waitForMoreWork() = synchronized { + do { wait() } while (todo.isEmpty) + } + + /** called from Server */ + def moreWork(): Boolean = synchronized { + todo.nonEmpty + } + + /** Called from server */ + def nextWorkItem(): Option[Action] = synchronized { + if (!todo.isEmpty) Some(todo.dequeue()) else None + } + + /** Called from client */ + def postWorkItem(action: Action) { + todo enqueue action + notify() + } + + /** Called from client */ + def cancel() = synchronized { + todo.clear() + } + + /** Called from client */ + def raise(exc: Exception) = synchronized { + todo.clear() + todo enqueue (() => throw exc) + } +} + -- cgit v1.2.3