Check for active while locked

This commit is contained in:
Mygod
2020-07-28 03:39:41 +08:00
parent 70ca91cd08
commit 83154e6d38

View File

@@ -198,13 +198,13 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
val result = input.readByte()
Timber.i("Received callback #$index: $result")
val callback = mutex.synchronized {
(callbackLookup[index] ?: error("Empty callback #$index")).also {
if (active) (callbackLookup[index] ?: error("Empty callback #$index")).also {
if (it.shouldRemove(result)) {
callbackLookup.remove(index)
it.active = false
}
}
}
} else null
} ?: break
if (isDebugEnabled) Log.d(TAG, "Received callback #$index: $result")
callback(input, result)
}