mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-21 01:00:54 +08:00
Fix bugs in threading in C backend
This commit is contained in:
parent
eeaa71072a
commit
731beb5cd5
@ -190,8 +190,8 @@ public class TThread extends TObject implements TRunnable {
|
||||
@Async
|
||||
public static native void sleep(long millis) throws TInterruptedException;
|
||||
|
||||
private static void sleep(long millis, final AsyncCallback<Void> callback) {
|
||||
final TThread current = currentThread();
|
||||
private static void sleep(long millis, AsyncCallback<Void> callback) {
|
||||
TThread current = currentThread();
|
||||
SleepHandler handler = new SleepHandler(current, callback);
|
||||
if (PlatformDetector.isLowLevel()) {
|
||||
handler.scheduleId = EventQueue.offer(handler, System.currentTimeMillis() + millis);
|
||||
|
@ -58,6 +58,7 @@ import org.teavm.model.util.BasicBlockMapper;
|
||||
import org.teavm.model.util.InstructionVariableMapper;
|
||||
import org.teavm.model.util.ProgramUtils;
|
||||
import org.teavm.model.util.TransitionExtractor;
|
||||
import org.teavm.runtime.Fiber;
|
||||
|
||||
public class Inlining {
|
||||
private IntArrayList depthsByBlock;
|
||||
@ -177,7 +178,7 @@ public class Inlining {
|
||||
if (step == null) {
|
||||
return false;
|
||||
}
|
||||
List<PlanEntry> plan = buildPlan(program, -1, step);
|
||||
List<PlanEntry> plan = buildPlan(program, -1, step, method);
|
||||
if (plan.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -328,7 +329,7 @@ public class Inlining {
|
||||
execPlan(program, planEntry.innerPlan, firstInlineBlock.getIndex());
|
||||
}
|
||||
|
||||
private List<PlanEntry> buildPlan(Program program, int depth, InliningStep step) {
|
||||
private List<PlanEntry> buildPlan(Program program, int depth, InliningStep step, MethodReference method) {
|
||||
List<PlanEntry> plan = new ArrayList<>();
|
||||
int originalDepth = depth;
|
||||
|
||||
@ -355,6 +356,11 @@ public class Inlining {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invoke.getMethod().getClassName().equals(Fiber.class.getName())
|
||||
!= method.getClassName().equals(Fiber.class.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MethodReader invokedMethod = getMethod(invoke.getMethod());
|
||||
if (invokedMethod == null || invokedMethod.getProgram() == null
|
||||
|| invokedMethod.getProgram().basicBlockCount() == 0
|
||||
@ -376,7 +382,7 @@ public class Inlining {
|
||||
entry.targetBlock = block.getIndex();
|
||||
entry.targetInstruction = insn;
|
||||
entry.program = invokedProgram;
|
||||
entry.innerPlan.addAll(buildPlan(invokedProgram, depth + 1, innerStep));
|
||||
entry.innerPlan.addAll(buildPlan(invokedProgram, depth + 1, innerStep, invokedMethod.getReference()));
|
||||
entry.depth = depth;
|
||||
entry.method = invokedMethod.getReference();
|
||||
plan.add(entry);
|
||||
|
@ -64,7 +64,7 @@ public final class EventQueue {
|
||||
}
|
||||
|
||||
public static void process() {
|
||||
while (!finished) {
|
||||
while (size > 0 && !finished) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,16 @@ public final class EventQueue {
|
||||
}
|
||||
|
||||
private static void remove(int index) {
|
||||
Node item = data[size - 1];
|
||||
--size;
|
||||
if (index < size) {
|
||||
data[index] = data[size];
|
||||
update(index);
|
||||
}
|
||||
data[size] = null;
|
||||
}
|
||||
|
||||
private static void update(int index) {
|
||||
Node item = data[index];
|
||||
while (true) {
|
||||
int left = index * 2 + 1;
|
||||
int right = left + 1;
|
||||
|
@ -211,12 +211,7 @@ public class Fiber {
|
||||
}
|
||||
|
||||
static void startMain() {
|
||||
start(() -> {
|
||||
runMain();
|
||||
if (!current().isSuspending()) {
|
||||
EventQueue.stop();
|
||||
}
|
||||
});
|
||||
start(Fiber::runMain);
|
||||
}
|
||||
|
||||
static native void runMain();
|
||||
@ -228,7 +223,7 @@ public class Fiber {
|
||||
current = former;
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
void resume() {
|
||||
state = STATE_RESUMING;
|
||||
start();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user