Fix counter not protected by mutex
This commit is contained in:
@@ -245,13 +245,14 @@ class RootServer {
|
|||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
suspend fun <T : Parcelable?> execute(command: RootCommand<T>, classLoader: ClassLoader?): T {
|
suspend fun <T : Parcelable?> execute(command: RootCommand<T>, classLoader: ClassLoader?): T {
|
||||||
val future = CompletableDeferred<T>()
|
val future = CompletableDeferred<T>()
|
||||||
|
val callback = mutex.withLock {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val callback = Callback.Ordinary(this, counter, classLoader, future as CompletableDeferred<Parcelable?>)
|
val callback = Callback.Ordinary(this, counter, classLoader, future as CompletableDeferred<Parcelable?>)
|
||||||
mutex.withLock {
|
|
||||||
if (active) {
|
if (active) {
|
||||||
callbackLookup[counter] = callback
|
callbackLookup[counter] = callback
|
||||||
sendLocked(command)
|
sendLocked(command)
|
||||||
} else future.cancel()
|
} else future.cancel()
|
||||||
|
callback
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return future.await()
|
return future.await()
|
||||||
@@ -275,13 +276,14 @@ class RootServer {
|
|||||||
else -> throw IllegalArgumentException("Unsupported channel capacity $it")
|
else -> throw IllegalArgumentException("Unsupported channel capacity $it")
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
val callback = mutex.withLock {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val callback = Callback.Channel(this@RootServer, counter, classLoader, this as SendChannel<Parcelable?>)
|
val callback = Callback.Channel(this@RootServer, counter, classLoader, this as SendChannel<Parcelable?>)
|
||||||
mutex.withLock {
|
|
||||||
if (active) {
|
if (active) {
|
||||||
callbackLookup[counter] = callback
|
callbackLookup[counter] = callback
|
||||||
sendLocked(command)
|
sendLocked(command)
|
||||||
} else callback.finish.cancel()
|
} else callback.finish.cancel()
|
||||||
|
callback
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
callback.finish.await()
|
callback.finish.await()
|
||||||
|
|||||||
Reference in New Issue
Block a user