Commit efa404d0 authored by Him188's avatar Him188

Try fix compilation bug

parent 69ff3776
...@@ -90,6 +90,15 @@ internal object EventListenerManager { ...@@ -90,6 +90,15 @@ internal object EventListenerManager {
private val lock = atomic(false) private val lock = atomic(false)
private fun setLockValue(value: Boolean) {
lock.value = value
}
@Suppress("BooleanLiteralArgument")
private fun trySetLockTrue(): Boolean {
return lock.compareAndSet(false, true)
}
@Suppress("UNCHECKED_CAST", "BooleanLiteralArgument") @Suppress("UNCHECKED_CAST", "BooleanLiteralArgument")
internal tailrec fun <E : Event> get(clazz: KClass<out E>): EventListeners<E> { internal tailrec fun <E : Event> get(clazz: KClass<out E>): EventListeners<E> {
registries.forEach { registries.forEach {
...@@ -97,10 +106,10 @@ internal object EventListenerManager { ...@@ -97,10 +106,10 @@ internal object EventListenerManager {
return it.listeners as EventListeners<E> return it.listeners as EventListeners<E>
} }
} }
if (lock.compareAndSet(false, true)) { if (trySetLockTrue()) {
val registry = Registry(clazz, EventListeners()) val registry = Registry(clazz, EventListeners())
registries.addLast(registry) registries.addLast(registry)
lock.value = false setLockValue(false)
return registry.listeners as EventListeners<E> return registry.listeners as EventListeners<E>
} }
return get(clazz) return get(clazz)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment