summaryrefslogtreecommitdiff
path: root/src/actors/scala/actors/ActorGC.scala
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-09-24 10:37:50 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-09-24 10:37:50 +0000
commitcabb954584a0ed6c65dc0ace90ad6af14e00a390 (patch)
tree32d5c0355b187780e2f8d7871cb9896d5c37dac5 /src/actors/scala/actors/ActorGC.scala
parent87a113f132473036e6b975962fdb5cea8364b532 (diff)
downloadscala-cabb954584a0ed6c65dc0ace90ad6af14e00a390.tar.gz
scala-cabb954584a0ed6c65dc0ace90ad6af14e00a390.tar.bz2
scala-cabb954584a0ed6c65dc0ace90ad6af14e00a390.zip
Fixed #2359.
Diffstat (limited to 'src/actors/scala/actors/ActorGC.scala')
-rw-r--r--src/actors/scala/actors/ActorGC.scala17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/actors/scala/actors/ActorGC.scala b/src/actors/scala/actors/ActorGC.scala
index 67493e91cd..2725e29109 100644
--- a/src/actors/scala/actors/ActorGC.scala
+++ b/src/actors/scala/actors/ActorGC.scala
@@ -13,6 +13,7 @@ package scala.actors
import java.lang.ref.{Reference, WeakReference, ReferenceQueue}
import scala.collection.mutable.{HashMap, HashSet}
+import scala.actors.scheduler.TerminationMonitor
/**
* ActorGC keeps track of the number of live actors being managed by a
@@ -24,10 +25,8 @@ import scala.collection.mutable.{HashMap, HashSet}
* (e.g. act method finishes, exit explicitly called, an exception is thrown),
* the ActorGC is informed via the <code>terminated</code> method.
*/
-trait ActorGC extends IScheduler {
-
- private var pendingReactions = 0
- private val termHandlers = new HashMap[Reactor, () => Unit]
+trait ActorGC extends TerminationMonitor {
+ self: IScheduler =>
/** Actors are added to refQ in newActor. */
private val refQ = new ReferenceQueue[Reactor]
@@ -40,7 +39,7 @@ trait ActorGC extends IScheduler {
private val refSet = new HashSet[Reference[t] forSome { type t <: Reactor }]
/** newActor is invoked whenever a new actor is started. */
- def newActor(a: Reactor) = synchronized {
+ override def newActor(a: Reactor) = synchronized {
// registers a reference to the actor with the ReferenceQueue
val wr = new WeakReference[Reactor](a, refQ)
refSet += wr
@@ -48,7 +47,7 @@ trait ActorGC extends IScheduler {
}
/** Removes unreachable actors from refSet. */
- protected def gc() = synchronized {
+ protected override def gc() = synchronized {
// check for unreachable actors
def drainRefQ() {
val wr = refQ.poll
@@ -66,17 +65,17 @@ trait ActorGC extends IScheduler {
println(this+": size of refSet: "+refSet.size)
}
- protected def allTerminated: Boolean = synchronized {
+ protected override def allTerminated: Boolean = synchronized {
pendingReactions <= 0
}
- def onTerminate(a: Reactor)(f: => Unit) = synchronized {
+ override def onTerminate(a: Reactor)(f: => Unit): Unit = synchronized {
termHandlers += (a -> (() => f))
}
/* Called only from <code>Reaction</code>.
*/
- def terminated(a: Reactor) = synchronized {
+ override def terminated(a: Reactor) = synchronized {
// execute registered termination handler (if any)
termHandlers.get(a) match {
case Some(handler) =>