mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-08 16:56:25 +00:00
Forcefully shove stuff into other stuff
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user