mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Proper fix for recent bug in C backend. Fix Thread.daemon flag
This commit is contained in:
parent
0dc170dad2
commit
d2a7e31eca
|
@ -41,10 +41,6 @@ public class TThread extends TObject implements TRunnable {
|
|||
private boolean alive = true;
|
||||
TRunnable target;
|
||||
|
||||
static {
|
||||
mainThread.setDaemon(true);
|
||||
}
|
||||
|
||||
public TThread() {
|
||||
this(null, null);
|
||||
}
|
||||
|
@ -65,7 +61,11 @@ public class TThread extends TObject implements TRunnable {
|
|||
|
||||
public void start() {
|
||||
if (PlatformDetector.isLowLevel()) {
|
||||
EventQueue.offer(() -> Fiber.start(this::runThread));
|
||||
boolean daemon = this.daemon;
|
||||
if (!daemon) {
|
||||
Fiber.userThreadCount++;
|
||||
}
|
||||
EventQueue.offer(() -> Fiber.start(this::runThread, daemon));
|
||||
} else {
|
||||
Platform.startThread(this::runThread);
|
||||
}
|
||||
|
@ -207,8 +207,12 @@ public class TThread extends TObject implements TRunnable {
|
|||
TThread current = currentThread();
|
||||
SleepHandler handler = new SleepHandler(current, callback);
|
||||
if (PlatformDetector.isLowLevel()) {
|
||||
handler.scheduleId = EventQueue.offer(handler, System.currentTimeMillis() + millis);
|
||||
current.interruptHandler = handler;
|
||||
if (current.interruptedFlag) {
|
||||
handler.interrupted();
|
||||
} else {
|
||||
handler.scheduleId = EventQueue.offer(handler, System.currentTimeMillis() + millis);
|
||||
current.interruptHandler = handler;
|
||||
}
|
||||
} else {
|
||||
int intMillis = millis < Integer.MAX_VALUE ? (int) millis : Integer.MAX_VALUE;
|
||||
handler.scheduleId = Platform.schedule(handler, intMillis);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class Fiber {
|
|||
public static final int STATE_RUNNING = 0;
|
||||
public static final int STATE_SUSPENDING = 1;
|
||||
public static final int STATE_RESUMING = 2;
|
||||
private static int daemonCount = 1;
|
||||
public static int userThreadCount = 1;
|
||||
|
||||
private int[] intValues;
|
||||
private int intTop;
|
||||
|
@ -41,11 +41,13 @@ public class Fiber {
|
|||
private FiberRunner runner;
|
||||
private Object result;
|
||||
private Throwable exception;
|
||||
private boolean daemon;
|
||||
|
||||
private static Fiber current;
|
||||
|
||||
private Fiber(FiberRunner runner) {
|
||||
private Fiber(FiberRunner runner, boolean daemon) {
|
||||
this.runner = runner;
|
||||
this.daemon = daemon;
|
||||
}
|
||||
|
||||
public void push(int value) {
|
||||
|
@ -207,12 +209,12 @@ public class Fiber {
|
|||
|
||||
static native void setCurrentThread(Thread thread);
|
||||
|
||||
public static void start(FiberRunner runner) {
|
||||
new Fiber(runner).start();
|
||||
public static void start(FiberRunner runner, boolean daemon) {
|
||||
new Fiber(runner, daemon).start();
|
||||
}
|
||||
|
||||
static void startMain() {
|
||||
start(Fiber::runMain);
|
||||
start(Fiber::runMain, false);
|
||||
}
|
||||
|
||||
static native void runMain();
|
||||
|
@ -222,7 +224,7 @@ public class Fiber {
|
|||
current = this;
|
||||
runner.run();
|
||||
current = former;
|
||||
if (!isSuspending() && Thread.currentThread().isDaemon() && --daemonCount == 0) {
|
||||
if (!isSuspending() && !daemon && --userThreadCount == 0) {
|
||||
EventQueue.stop();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user