commit 1a14c431510eafb8e35349db993539a084a0c366
parent d5b47e3e17a870f224e6103542fb5f349bf87c6f
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sun, 15 Sep 2024 14:10:49 +0200
fix(native): lock database
- call the runnable even if there is no mutex found
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/native/rust/src/modules/sqlite_hook.rs b/native/rust/src/modules/sqlite_hook.rs
@@ -50,19 +50,24 @@ pub fn lock_database(mut env: JNIEnv, _: *mut c_void, filename: JString, runnabl
let database_filename = get_jni_string(&mut env, filename).expect("Failed to get database filename");
let mutex = SQLITE3_MUTEX_MAP.lock().unwrap().get(&database_filename).map(|mutex| *mutex);
+ let call_runnable = || {
+ env.call_method(runnable, "run", "()V", &[]).expect("Failed to call run method");
+ };
+
if let Some(mut mutex) = mutex {
if unsafe { libc::pthread_mutex_lock(addr_of_mut!(mutex)) } != 0 {
error!("pthread_mutex_lock failed");
return;
}
- env.call_method(runnable, "run", "()V", &[]).expect("Failed to call run method");
+ call_runnable();
if unsafe { libc::pthread_mutex_unlock(addr_of_mut!(mutex)) } != 0 {
error!("pthread_mutex_unlock failed");
}
} else {
warn!("No mutex found for database: {}", database_filename);
+ call_runnable();
}
}