Revert "threading testing"

This reverts commit 9ba573af
This commit is contained in:
gnembon committed 2019-12-17 11:59:23 -04:00
1 parent 423701d4d7
commit 3295ca2af9
3 files changed
+14 -47

No files matched your search

@@ -944,18 +944,14 @@ public class CarpetExpression
this.expr.addLazyFunction("set", -1, (c, t, lv) -> this.expr.addLazyFunction("set", -1, (c, t, lv) ->
{ {
CarpetSettings.LOG.error("starting");
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
ServerWorld world = cc.s.getWorld(); ServerWorld world = cc.s.getWorld();
if (lv.size() < 2 || lv.size() % 2 == 1) if (lv.size() < 2 || lv.size() % 2 == 1)
throw new InternalExpressionException("'set' should have at least 2 params and odd attributes"); throw new InternalExpressionException("'set' should have at least 2 params and odd attributes");
BlockValue.LocatorResult targetLocator = BlockValue.fromParams(cc, lv, 0); BlockValue.LocatorResult targetLocator = BlockValue.fromParams(cc, lv, 0);
BlockValue.LocatorResult sourceLocator = BlockValue.fromParams(cc, lv, targetLocator.offset, true); BlockValue.LocatorResult sourceLocator = BlockValue.fromParams(cc, lv, targetLocator.offset, true);
CarpetSettings.LOG.error("dafuq");
BlockState sourceBlockState = sourceLocator.block.getBlockState(); BlockState sourceBlockState = sourceLocator.block.getBlockState();
CarpetSettings.LOG.error("finish dafuq");
BlockState targetBlockState = world.getBlockState(targetLocator.block.getPos()); BlockState targetBlockState = world.getBlockState(targetLocator.block.getPos());
CarpetSettings.LOG.error("finish dafuq 2");
if (sourceLocator.offset < lv.size()) if (sourceLocator.offset < lv.size())
{ {
StateFactory<Block, BlockState> states = sourceBlockState.getBlock().getStateFactory(); StateFactory<Block, BlockState> states = sourceBlockState.getBlock().getStateFactory();
@@ -969,7 +965,6 @@ public class CarpetExpression
sourceBlockState = setProperty(property, paramString, paramValue, sourceBlockState); sourceBlockState = setProperty(property, paramString, paramValue, sourceBlockState);
} }
} }
CarpetSettings.LOG.error("finish properties got");
CompoundTag data = sourceLocator.block.getData(); CompoundTag data = sourceLocator.block.getData();
@@ -1,6 +1,5 @@
package carpet.script.value; package carpet.script.value;
import carpet.CarpetSettings;
import carpet.script.Context; import carpet.script.Context;
import carpet.script.Expression; import carpet.script.Expression;
import carpet.script.Tokenizer; import carpet.script.Tokenizer;
@@ -10,7 +9,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@@ -19,13 +17,9 @@ import java.util.function.Supplier;
public class ThreadValue extends Value public class ThreadValue extends Value
{ {
private CompletableFuture<Value> taskFuture; private CompletableFuture<Value> taskFuture;
//public static ThreadLocal<Boolean> joining = ThreadLocal.withInitial(() -> false);
public final static Map<Thread,Integer> waitingTreads = new ConcurrentHashMap<>();
public static Map<Thread,Integer> joinRequestedThreads = new ConcurrentHashMap<>();
private long id; private long id;
private final Object lock; private final Object lock;
//private final boolean[] started; private final boolean[] started;
private Thread executingThread;
private Supplier<Value>task; private Supplier<Value>task;
private static long sequence = 0L; private static long sequence = 0L;
@@ -35,20 +29,18 @@ public class ThreadValue extends Value
{ {
id = sequence++; id = sequence++;
lock = new Object(); lock = new Object();
executingThread = null; started = new boolean[]{false};
//started = new boolean[]{false};
task = () -> task = () ->
{ {
if (executingThread == null) if (!started[0])
{ {
CarpetSettings.LOG.error("Setting the thread"); started[0] = true;
executingThread = Thread.currentThread();
return function.lazyEval(ctx, Context.NONE, expr, token, Collections.emptyList()).evalValue(ctx); return function.lazyEval(ctx, Context.NONE, expr, token, Collections.emptyList()).evalValue(ctx);
} }
return null; return null;
}; };
taskFuture = CompletableFuture.supplyAsync( taskFuture = CompletableFuture.supplyAsync(
() -> { synchronized (lock) { CarpetSettings.LOG.error("getting in future"); Value ret = task.get(); CarpetSettings.LOG.error("gotten in future"); return ret;} }, () -> { synchronized (lock) { return task.get(); } },
executorServices.computeIfAbsent(pool, (v) -> (ThreadPoolExecutor)Executors.newCachedThreadPool()) executorServices.computeIfAbsent(pool, (v) -> (ThreadPoolExecutor)Executors.newCachedThreadPool())
); );
Thread.yield(); Thread.yield();
@@ -68,45 +60,26 @@ public class ThreadValue extends Value
public Value join() public Value join()
{ {
CarpetSettings.LOG.error("in join "+id); if (!started[0])
if (executingThread == null)
{ {
CarpetSettings.LOG.error("not started "+id); synchronized (lock)
Value res;
waitingTreads.put(Thread.currentThread(), 1);
try
{ {
CarpetSettings.LOG.error(" getting result "+id); if (!started[0])
res = task.get(); {
CarpetSettings.LOG.error(" result got "+id); Value res = task.get();
taskFuture.complete(res);
return res;
}
} }
finally
{
waitingTreads.remove(Thread.currentThread());
}
taskFuture.complete(res);
return res;
} }
try try
{ {
synchronized (waitingTreads)
{
if (waitingTreads.containsKey(executingThread))
throw new InternalExpressionException("Cannot wait/join on world accessing thread");
waitingTreads.put(executingThread, 1);
}
CarpetSettings.LOG.error("getting future "+id);
return taskFuture.get(); return taskFuture.get();
} }
catch (InterruptedException | ExecutionException e) catch (InterruptedException | ExecutionException e)
{ {
return Value.NULL; return Value.NULL;
} }
finally
{
waitingTreads.remove(executingThread);
CarpetSettings.LOG.error(" future gotten "+id);
}
} }
public boolean isFinished() public boolean isFinished()
@@ -120,7 +93,7 @@ public class ThreadValue extends Value
{ {
if (!taskFuture.isDone()) if (!taskFuture.isDone())
{ {
executingThread = Thread.currentThread(); started[0] = true;
taskFuture.complete(Value.NULL); taskFuture.complete(Value.NULL);
} }
} }
-1
View File
@@ -143,7 +143,6 @@
"FallingBlockEntity_scarpetEventsMixin", "FallingBlockEntity_scarpetEventsMixin",
"ChunkTicketManager_scarpetMixin", "ChunkTicketManager_scarpetMixin",
"ServerChunkManager_scarpetMixin", "ServerChunkManager_scarpetMixin",
"ServerChunkManager_scarpetThreadingProtectionMixin",
"PistonBlock_movableTEMixin", "PistonBlock_movableTEMixin",