diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actors/scala/actors/scheduler/SingleThreadedEventLoopScheduler.scala | 69 | ||||
-rw-r--r-- | src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala | 38 |
2 files changed, 32 insertions, 75 deletions
diff --git a/src/actors/scala/actors/scheduler/SingleThreadedEventLoopScheduler.scala b/src/actors/scala/actors/scheduler/SingleThreadedEventLoopScheduler.scala deleted file mode 100644 index 539916590e..0000000000 --- a/src/actors/scala/actors/scheduler/SingleThreadedEventLoopScheduler.scala +++ /dev/null @@ -1,69 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2005-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.actors -package scheduler - -import scala.collection.mutable.Queue - -/** - * This scheduler executes actor tasks on the current thread. - * - * @author Philipp Haller - */ -class SingleThreadedEventLoopScheduler extends IScheduler { - - private val tasks = new Queue[Runnable] - - /** The maximum number of nested tasks that are run - * without unwinding the call stack. - */ - protected var maxNesting = 10 - - private var curNest = 0 - private var isShutdown = false - - def execute(task: Runnable) { - if (curNest < maxNesting) { - curNest += 1 - task.run() - } else { - curNest = 0 - tasks += task - } - } - - def execute(fun: => Unit): Unit = - execute(new Runnable { - def run() { fun } - }) - - def shutdown() { - isShutdown = false - while (!tasks.isEmpty) { - val task = tasks.dequeue() - task.run() - } - isShutdown = true - } - - def newActor(actor: Reactor) {} - def terminated(actor: Reactor) {} - - // TODO: run termination handlers at end of shutdown. - def onTerminate(actor: Reactor)(f: => Unit) {} - - def isActive = - !isShutdown - - def managedBlock(blocker: scala.concurrent.ManagedBlocker) { - blocker.block() - } -} diff --git a/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala b/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala index 4ad865a15d..0a9c41a0c0 100644 --- a/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala +++ b/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala @@ -11,17 +11,33 @@ package scala.actors package scheduler +import scala.collection.mutable.Queue + /** - * This scheduler executes the tasks of an actor on a single - * thread (the current thread). + * This scheduler executes actor tasks on the current thread. * - * @version 0.9.18 * @author Philipp Haller */ class SingleThreadedScheduler extends IScheduler { + private val tasks = new Queue[Runnable] + + /** The maximum number of nested tasks that are run + * without unwinding the call stack. + */ + protected val maxNesting = 10 + + private var curNest = 0 + private var isShutdown = false + def execute(task: Runnable) { - task.run() + if (curNest < maxNesting) { + curNest += 1 + task.run() + } else { + curNest = 0 + tasks += task + } } def execute(fun: => Unit): Unit = @@ -29,13 +45,23 @@ class SingleThreadedScheduler extends IScheduler { def run() { fun } }) - def shutdown() {} + def shutdown() { + isShutdown = false + while (!tasks.isEmpty) { + val task = tasks.dequeue() + task.run() + } + isShutdown = true + } def newActor(actor: Reactor) {} def terminated(actor: Reactor) {} + + // TODO: run termination handlers at end of shutdown. def onTerminate(actor: Reactor)(f: => Unit) {} - def isActive = true + def isActive = + !isShutdown def managedBlock(blocker: scala.concurrent.ManagedBlocker) { blocker.block() |