Skip to content

Commit

Permalink
Uses a copy on write set to make debug event subscribers thread safe
Browse files Browse the repository at this point in the history
Summary: Uses a copy on write set to make debug event subscribers thread safe

Differential Revision: D55246460

fbshipit-source-id: c1fcf1c645b7c99f9d7f99a1840bae016d02829c
  • Loading branch information
adityasharat authored and facebook-github-bot committed Mar 22, 2024
1 parent 047d69d commit 6451d74
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.facebook.rendercore.debug
import com.facebook.kotlin.compilerplugins.dataclassgenerate.annotation.DataClassGenerate
import com.facebook.rendercore.LogLevel
import com.facebook.rendercore.debug.DebugEvent.Companion.All
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -182,7 +183,7 @@ object DebugEventDispatcher {
minLogLevelRef.set(value)
}

private val mutableSubscribers: MutableSet<DebugEventSubscriber> = mutableSetOf()
private val mutableSubscribers: MutableSet<DebugEventSubscriber> = CopyOnWriteArraySet()

val subscribers: Set<DebugEventSubscriber>
@Synchronized get() = mutableSubscribers
Expand Down Expand Up @@ -258,8 +259,7 @@ object DebugEventDispatcher {
*/
@JvmStatic
fun generateTraceIdentifier(type: String): Int? =
if (subscribers.isNotEmpty() &&
subscribers.any { type in it.events || DebugEvent.All in it.events }) {
if (subscribers.isNotEmpty() && subscribers.any { type in it.events || All in it.events }) {
lastTraceIdentifier.getAndIncrement()
} else {
null
Expand Down

0 comments on commit 6451d74

Please sign in to comment.