summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/WorkScheduler.scala')
-rw-r--r--src/compiler/scala/tools/nsc/util/WorkScheduler.scala43
1 files changed, 43 insertions, 0 deletions
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)
+ }
+}
+