From 9194b37a8d402b67e41e941fddb4a741bf8eb16f Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 8 Feb 2013 17:17:23 -0800 Subject: [nomaster] refactor AdaptedForkJoinTask, uncaughtExceptionHandler Inlined AdaptedForkJoinTask, made uncaughtExceptionHandler private[this]. This is necessary to maintain binary compatibility with 2.10.0. --- bincompat-forward.whitelist.conf | 20 ++++++------- .../concurrent/impl/ExecutionContextImpl.scala | 33 ++++++++++------------ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/bincompat-forward.whitelist.conf b/bincompat-forward.whitelist.conf index ab43b3015f..a870288ffb 100644 --- a/bincompat-forward.whitelist.conf +++ b/bincompat-forward.whitelist.conf @@ -44,16 +44,16 @@ filter { # matchName="scala.concurrent.BatchingExecutor" # problemName=MissingClassProblem # }, - { - # private[concurrent] - matchName="scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask" - problemName=MissingClassProblem - }, - { - # private[concurrent] - matchName="scala.concurrent.impl.ExecutionContextImpl.scala$concurrent$impl$ExecutionContextImpl$$uncaughtExceptionHandler" - problemName=MissingMethodProblem - }, + # { + # # private[concurrent] + # matchName="scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask" + # problemName=MissingClassProblem + # }, + # { + # # private[concurrent] + # matchName="scala.concurrent.impl.ExecutionContextImpl.scala$concurrent$impl$ExecutionContextImpl$$uncaughtExceptionHandler" + # problemName=MissingMethodProblem + # }, { # private nested class became private top-level class to fix SI-7018 matchName="scala.reflect.macros.NonemptyAttachments" diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala index 77625e381c..43b437dbc6 100644 --- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala +++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala @@ -25,7 +25,7 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter: case some => some } - private val uncaughtExceptionHandler: Thread.UncaughtExceptionHandler = new Thread.UncaughtExceptionHandler { + private[this] val uncaughtExceptionHandler: Thread.UncaughtExceptionHandler = new Thread.UncaughtExceptionHandler { def uncaughtException(thread: Thread, cause: Throwable): Unit = reporter(cause) } @@ -96,11 +96,24 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter: } } + def execute(runnable: Runnable): Unit = executor match { case fj: ForkJoinPool => val fjt = runnable match { case t: ForkJoinTask[_] => t - case r => new ExecutionContextImpl.AdaptedForkJoinTask(r) + case runnable => new ForkJoinTask[Unit] { + final override def setRawResult(u: Unit): Unit = () + final override def getRawResult(): Unit = () + final override def exec(): Boolean = try { runnable.run(); true } catch { + case anything: Throwable ⇒ + val t = Thread.currentThread + t.getUncaughtExceptionHandler match { + case null ⇒ + case some ⇒ some.uncaughtException(t, anything) + } + throw anything + } + } } Thread.currentThread match { case fjw: ForkJoinWorkerThread if fjw.getPool eq fj => fjt.fork() @@ -112,23 +125,7 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter: def reportFailure(t: Throwable) = reporter(t) } - private[concurrent] object ExecutionContextImpl { - - final class AdaptedForkJoinTask(runnable: Runnable) extends ForkJoinTask[Unit] { - final override def setRawResult(u: Unit): Unit = () - final override def getRawResult(): Unit = () - final override def exec(): Boolean = try { runnable.run(); true } catch { - case anything: Throwable ⇒ - val t = Thread.currentThread - t.getUncaughtExceptionHandler match { - case null ⇒ - case some ⇒ some.uncaughtException(t, anything) - } - throw anything - } - } - def fromExecutor(e: Executor, reporter: Throwable => Unit = ExecutionContext.defaultReporter): ExecutionContextImpl = new ExecutionContextImpl(e, reporter) def fromExecutorService(es: ExecutorService, reporter: Throwable => Unit = ExecutionContext.defaultReporter): ExecutionContextImpl with ExecutionContextExecutorService = new ExecutionContextImpl(es, reporter) with ExecutionContextExecutorService { -- cgit v1.2.3