summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-05-25 22:00:48 +0000
committerMartin Odersky <odersky@gmail.com>2009-05-25 22:00:48 +0000
commitc5aa57c2d573f0205615db6690139e0e4b555492 (patch)
tree3041ad7966799bcc4d69a78fd2a92beef76f7afc /src/compiler/scala/tools/nsc/util/WorkScheduler.scala
parent213285991d73a80b322c55000c69633893dccb80 (diff)
downloadscala-c5aa57c2d573f0205615db6690139e0e4b555492.tar.gz
scala-c5aa57c2d573f0205615db6690139e0e4b555492.tar.bz2
scala-c5aa57c2d573f0205615db6690139e0e4b555492.zip
new presentation compiler design
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/WorkScheduler.scala')
-rw-r--r--src/compiler/scala/tools/nsc/util/WorkScheduler.scala42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/util/WorkScheduler.scala b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
index 7bcd3b7a8e..cd4d805701 100644
--- a/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
+++ b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
@@ -7,37 +7,59 @@ class WorkScheduler {
type Action = () => Unit
private var todo = new Queue[Action]
+ private var except: Option[Exception] = None
+ private var working = false
- /** Called from server */
+ /** Called from server: block until todo list is nonempty */
def waitForMoreWork() = synchronized {
do { wait() } while (todo.isEmpty)
}
- /** called from Server */
+ /** called from Server: test whether todo list is nonempty */
def moreWork(): Boolean = synchronized {
todo.nonEmpty
}
- /** Called from server */
+ /** Called from server: get first action in todo list, and pop it off */
def nextWorkItem(): Option[Action] = synchronized {
- if (!todo.isEmpty) Some(todo.dequeue()) else None
+ if (!todo.isEmpty) {
+ working = true
+ Some(todo.dequeue())
+ } else None
}
- /** Called from client */
+ /** Called from server: raise any exception posted by client */
+ def pollException() = synchronized {
+ except match {
+ case Some(exc) => throw exc
+ case None =>
+ }
+ }
+
+ /** Called from server: mark workitem as finished (influences
+ * meaning of raise)
+ */
+ def doneWorkItem() = synchronized {
+ working = false
+ }
+
+ /** Called from client: have action executed by server */
def postWorkItem(action: Action) {
todo enqueue action
notify()
}
- /** Called from client */
- def cancel() = synchronized {
+ /** Called from client: cancel all queued actions */
+ def cancelQueued() = synchronized {
todo.clear()
}
- /** Called from client */
+ /** Called from client:
+ * If work in progress, raise an exception in it next
+ * time pollException is called.
+ */
def raise(exc: Exception) = synchronized {
- todo.clear()
- todo enqueue (() => throw exc)
+ if (working) except = Some(exc)
}
}