Skip to content

Commit

Permalink
Make discovery thread start function thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Nov 10, 2024
1 parent 284af83 commit b4a26a4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions android/app/src/main/java/dev/danielc/fujiapp/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class Backend extends Camlib {
static {
System.loadLibrary("fudge");
cInit();
}

// Discovery errors
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b4a26a4

Please sign in to comment.