Forcefully shove stuff into other stuff

This commit is contained in:
Daniel Mills
2020-11-10 00:49:28 -05:00
parent 50ffcceaf4
commit 4fc8a5ad0c
364 changed files with 2975 additions and 5303 deletions

View File

@@ -0,0 +1,60 @@
package com.volmit.iris.scaffold.parallel;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import com.volmit.iris.util.KList;
public class BurstExecutor
{
private ExecutorService executor;
private KList<CompletableFuture<Void>> futures;
public BurstExecutor(ExecutorService executor, int burstSizeEstimate)
{
this.executor = executor;
futures = new KList<CompletableFuture<Void>>(burstSizeEstimate);
}
public CompletableFuture<Void> queue(Runnable r)
{
synchronized(futures)
{
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
futures.add(c);
return c;
}
}
public BurstExecutor queue(Runnable[] r)
{
synchronized(futures)
{
for(Runnable i : r)
{
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
futures.add(c);
}
}
return this;
}
public void complete()
{
synchronized(futures)
{
try
{
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).get();
futures.clear();
}
catch(InterruptedException | ExecutionException e)
{
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,12 @@
package com.volmit.iris.scaffold.parallel;
import com.volmit.iris.scaffold.hunk.Hunk;
public interface BurstedHunk<T> extends Hunk<T>
{
public int getOffsetX();
public int getOffsetY();
public int getOffsetZ();
}

View File

@@ -0,0 +1,34 @@
package com.volmit.iris.scaffold.parallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MultiBurst
{
public static MultiBurst burst = new MultiBurst(Runtime.getRuntime().availableProcessors());
private ExecutorService service;
public MultiBurst(int tc)
{
service = Executors.newWorkStealingPool(tc);
}
public void burst(Runnable... r)
{
burst(r.length).queue(r).complete();
}
public BurstExecutor burst(int estimate)
{
return new BurstExecutor(service, estimate);
}
public BurstExecutor burst()
{
return burst(16);
}
public void lazy(Runnable o) {
service.execute(o);
}
}