mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 13:17:42 +02:00
feat(native): database lock
- refactor native
This commit is contained in:
@ -183,7 +183,7 @@ class SnapEnhance {
|
||||
val libName = param.arg<String>(2)
|
||||
if (libName != "client") return@hook
|
||||
unhook()
|
||||
appContext.native.initOnce(appContext.androidContext.classLoader)
|
||||
appContext.native.initOnce()
|
||||
appContext.native.nativeUnaryCallCallback = { request ->
|
||||
appContext.event.post(NativeUnaryCallEvent(request.uri, request.buffer)) {
|
||||
request.buffer = buffer
|
||||
|
@ -17,6 +17,7 @@ import me.rhunk.snapenhance.common.util.ktx.getStringOrNull
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
|
||||
import me.rhunk.snapenhance.core.ModContext
|
||||
import me.rhunk.snapenhance.core.manager.Manager
|
||||
import me.rhunk.snapenhance.nativelib.NativeLib
|
||||
|
||||
|
||||
enum class DatabaseType(
|
||||
@ -59,9 +60,15 @@ class DatabaseAccess(
|
||||
}
|
||||
|
||||
|
||||
private inline fun <T> SQLiteDatabase.performOperation(crossinline query: SQLiteDatabase.() -> T?): T? {
|
||||
private fun <T> SQLiteDatabase.performOperation(query: SQLiteDatabase.() -> T?): T? {
|
||||
return runCatching {
|
||||
synchronized(this) {
|
||||
if (NativeLib.initialized && openedDatabases[DatabaseType.ARROYO] == this) {
|
||||
var result: T? = null
|
||||
context.native.lockNativeDatabase(DatabaseType.ARROYO.fileName) {
|
||||
result = query()
|
||||
}
|
||||
result
|
||||
} else synchronized(this) {
|
||||
query()
|
||||
}
|
||||
}.onFailure {
|
||||
|
Reference in New Issue
Block a user