mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-01 00:33:47 +00:00
Use AtomicBoolean
This commit is contained in:
parent
4e2ecdb920
commit
90013e486d
@ -37,6 +37,7 @@ import java.io.*
|
|||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
@ -420,20 +421,15 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
protected abstract suspend fun operations(): Boolean
|
protected abstract suspend fun operations(): Boolean
|
||||||
|
|
||||||
open suspend fun exec(): Boolean {
|
open suspend fun exec(): Boolean {
|
||||||
synchronized(Companion) {
|
if (haveActiveSession.getAndSet(true))
|
||||||
if (haveActiveSession)
|
return false
|
||||||
return false
|
|
||||||
haveActiveSession = true
|
|
||||||
}
|
|
||||||
val result = withContext(Dispatchers.IO) { operations() }
|
val result = withContext(Dispatchers.IO) { operations() }
|
||||||
synchronized(Companion) {
|
haveActiveSession.set(false)
|
||||||
haveActiveSession = false
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var haveActiveSession = false
|
private var haveActiveSession = AtomicBoolean(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user