From ed7cc67f19c0ce7f1e367f5263151a15ff6b8399 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 15 Jun 2015 14:11:50 +0200 Subject: [PATCH] thread-safe usage of performance counters list #KT-8046 Fixed --- .../src/org/jetbrains/kotlin/util/PerformanceCounter.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt b/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt index 4a5a1e77c85..a48fd1b7627 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt @@ -47,7 +47,10 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val public fun currentThreadCpuTime(): Long = threadMxBean.getCurrentThreadUserTime() public fun report(consumer: (String) -> Unit) { - allCounters.forEach { it.report(consumer) } + val countersCopy = synchronized(allCounters) { + allCounters.toTypedArray() + } + countersCopy.forEach { it.report(consumer) } } } @@ -55,7 +58,9 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val private var totalTimeNanos: Long = 0 init { - allCounters.add(this) + synchronized(allCounters) { + allCounters.add(this) + } } public fun increment() {