From 92a858eee87cdf912e68a1d30bb11aefde02b41e Mon Sep 17 00:00:00 2001 From: Derek Williams Date: Mon, 28 Feb 2011 11:48:51 -0700 Subject: [PATCH] Add locking in dispatchFuture --- .../scala/akka/dispatch/MessageHandling.scala | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala b/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala index cb102ba30d..6ac852d0cc 100644 --- a/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala +++ b/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala @@ -78,18 +78,22 @@ trait MessageDispatcher extends Logging { } else throw new IllegalActorStateException("Can't submit invocations to dispatcher since it's not started") private[akka] final def dispatchFuture(invocation: FutureInvocation): Unit = { - futures add invocation.uuid - if (active.isOff) { active.switchOn { start } } + guard withGuard { + futures add invocation.uuid + if (active.isOff) { active.switchOn { start } } + } invocation.future.onComplete { f => - futures remove invocation.uuid - if (futures.isEmpty && uuids.isEmpty) { - shutdownSchedule match { - case UNSCHEDULED => - shutdownSchedule = SCHEDULED - Scheduler.scheduleOnce(shutdownAction, timeoutMs, TimeUnit.MILLISECONDS) - case SCHEDULED => - shutdownSchedule = RESCHEDULED - case RESCHEDULED => //Already marked for reschedule + guard withGuard { + futures remove invocation.uuid + if (futures.isEmpty && uuids.isEmpty) { + shutdownSchedule match { + case UNSCHEDULED => + shutdownSchedule = SCHEDULED + Scheduler.scheduleOnce(shutdownAction, timeoutMs, TimeUnit.MILLISECONDS) + case SCHEDULED => + shutdownSchedule = RESCHEDULED + case RESCHEDULED => //Already marked for reschedule + } } } }