From b4a26a43cf03e7cc5e5ba4f3b0d34f23dd678ec0 Mon Sep 17 00:00:00 2001 From: Daniel C Date: Sat, 9 Nov 2024 19:15:57 -0500 Subject: [PATCH] Make discovery thread start function thread safe --- android/app/build.gradle | 4 ++-- .../src/main/java/dev/danielc/fujiapp/Backend.java | 11 ++--------- .../main/java/dev/danielc/fujiapp/MainActivity.java | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 1fce4ca..ba28d80 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "dev.danielc.fujiapp" minSdk 23 targetSdk 34 - versionCode 9 - versionName "0.2.0 (beta)" + versionCode 10 + versionName "0.2.1 (beta)" } buildTypes { diff --git a/android/app/src/main/java/dev/danielc/fujiapp/Backend.java b/android/app/src/main/java/dev/danielc/fujiapp/Backend.java index bd1425a..ee94639 100644 --- a/android/app/src/main/java/dev/danielc/fujiapp/Backend.java +++ b/android/app/src/main/java/dev/danielc/fujiapp/Backend.java @@ -16,6 +16,7 @@ public class Backend extends Camlib { static { System.loadLibrary("fudge"); + cInit(); } // Discovery errors @@ -55,14 +56,6 @@ public void run() { }).start(); } - private static boolean haveInited = false; - public static void init() { - if (!haveInited) { - cInit(); - } - haveInited = true; - } - /** Allocates initial memory */ public native static void cInit(); @@ -104,7 +97,7 @@ public static void init() { public native static View cFujiScriptsScreen(Context ctx); static Thread discoveryThread = null; - public static void discoveryThread(Context ctx) { + public static synchronized void discoveryThread(Context ctx) { // Not the greatest thread safety here if (discoveryThread != null) { Log.d("backend", "Discovery thread already running"); diff --git a/android/app/src/main/java/dev/danielc/fujiapp/MainActivity.java b/android/app/src/main/java/dev/danielc/fujiapp/MainActivity.java index d1b3cf9..f62a27a 100644 --- a/android/app/src/main/java/dev/danielc/fujiapp/MainActivity.java +++ b/android/app/src/main/java/dev/danielc/fujiapp/MainActivity.java @@ -178,7 +178,6 @@ public void run() { LibUI.buttonBackgroundResource = R.drawable.grey_button; LibUI.popupDrawableResource = R.drawable.border; - Backend.init(); wifi.setConnectivityManager((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE)); wifi.startNetworkListeners(this);