thread-safe usage of performance counters list
#KT-8046 Fixed
This commit is contained in:
@@ -47,7 +47,10 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val
|
|||||||
public fun currentThreadCpuTime(): Long = threadMxBean.getCurrentThreadUserTime()
|
public fun currentThreadCpuTime(): Long = threadMxBean.getCurrentThreadUserTime()
|
||||||
|
|
||||||
public fun report(consumer: (String) -> Unit) {
|
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
|
private var totalTimeNanos: Long = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
allCounters.add(this)
|
synchronized(allCounters) {
|
||||||
|
allCounters.add(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun increment() {
|
public fun increment() {
|
||||||
|
|||||||
Reference in New Issue
Block a user