Commit 90013e48 authored by topjohnwu's avatar topjohnwu

Use AtomicBoolean

parent 4e2ecdb9
......@@ -37,6 +37,7 @@ import java.io.*
import java.nio.ByteBuffer
import java.security.SecureRandom
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
......@@ -420,20 +421,15 @@ abstract class MagiskInstallImpl protected constructor(
protected abstract suspend fun operations(): Boolean
open suspend fun exec(): Boolean {
synchronized(Companion) {
if (haveActiveSession)
return false
haveActiveSession = true
}
if (haveActiveSession.getAndSet(true))
return false
val result = withContext(Dispatchers.IO) { operations() }
synchronized(Companion) {
haveActiveSession = false
}
haveActiveSession.set(false)
return result
}
companion object {
private var haveActiveSession = false
private var haveActiveSession = AtomicBoolean(false)
}
}
......
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