diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-11-09 11:57:57 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-11-09 11:57:57 +0000 |
commit | aa93e6f3b8686f20e6d16e177e5ec1e24d588096 (patch) | |
tree | 8da9006928ef899e2fd7dc8f08f35f298f9fd329 | |
parent | ea64259fa05e515b76798b891bee8eca8d9b9f05 (diff) | |
download | scala-aa93e6f3b8686f20e6d16e177e5ec1e24d588096.tar.gz scala-aa93e6f3b8686f20e6d16e177e5ec1e24d588096.tar.bz2 scala-aa93e6f3b8686f20e6d16e177e5ec1e24d588096.zip |
Fixed bug in receiveWithin.
-rw-r--r-- | src/actors/scala/actors/Actor.scala | 29 | ||||
-rw-r--r-- | src/actors/scala/actors/Channel.scala | 7 | ||||
-rw-r--r-- | src/actors/scala/actors/Scheduler.scala | 10 |
3 files changed, 32 insertions, 14 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index dcf5b64f4a..af2b477ccf 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -377,6 +377,8 @@ trait Actor extends OutputChannel[Any] { private var continue = false + private class ExitSuspendLoop extends Throwable + private[actors] def resetActor(): Unit = { suspendActor = () => { continue = false @@ -393,17 +395,26 @@ trait Actor extends OutputChannel[Any] { val ts = Platform.currentTime var waittime = msec continue = false - while(!continue) { - try { - wait(waittime) - } catch { - case t: InterruptedException => { - val now = Platform.currentTime - val waited = now-ts - waittime = msec-waited + var fromExc = false + + try { + while(!continue) { + try { + fromExc = false + wait(waittime) + } catch { + case t: InterruptedException => { + fromExc = true + val now = Platform.currentTime + val waited = now-ts + waittime = msec-waited + if (waittime < 0) { continue = true } + } } + if (!fromExc) throw new ExitSuspendLoop } - } + } catch { case _: ExitSuspendLoop => } + Debug.info("leaving suspendActorFor("+msec+")") } resumeActor = () => { diff --git a/src/actors/scala/actors/Channel.scala b/src/actors/scala/actors/Channel.scala index fa474f3fc1..20e1cd0f49 100644 --- a/src/actors/scala/actors/Channel.scala +++ b/src/actors/scala/actors/Channel.scala @@ -237,15 +237,20 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { // acquire lock because we might call wait() this.synchronized { isSuspended = true + received = null receiver.suspendActorFor(msec) - if (received == null) + Debug.info("received: "+received) + if (received == null) { + Debug.info("no message received after "+msec+" millis") if (f.isDefinedAt(TIMEOUT)) { + Debug.info("executing TIMEOUT action") isSuspended = false val result = f(TIMEOUT) return result } else error("unhandled timeout") + } } } } diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index ad2050c871..6d6345d11c 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -178,11 +178,11 @@ class TickedScheduler extends Thread with IScheduler { private var pendingReactions = new Stack[unit] def pendReaction: unit = { - Debug.info("pend reaction") + //Debug.info("pend reaction") pendingReactions push () } def unPendReaction: unit = { - Debug.info("unpend reaction") + //Debug.info("unpend reaction") if (!pendingReactions.isEmpty) pendingReactions.pop } @@ -239,9 +239,9 @@ class TickedScheduler extends Thread with IScheduler { } } // tasks.length > 0 else { - Debug.info("task queue empty") + //Debug.info("task queue empty") if (pendingReactions.isEmpty) { - Debug.info("no pending reactions") + //Debug.info("no pending reactions") // if all worker threads idle terminate if (workers.length == idle.length) { Debug.info("all threads idle, terminating") @@ -251,6 +251,8 @@ class TickedScheduler extends Thread with IScheduler { worker.running = false worker.interrupt() } + // terminate timer thread + TimerThread.t.interrupt() throw new QuitException } } |