9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 03:29:06 +00:00
This commit is contained in:
cyberpwn
2021-08-21 21:41:37 -04:00
parent b62e542801
commit 33812b3f4a
22 changed files with 113 additions and 355 deletions

View File

@@ -29,6 +29,8 @@ import java.util.concurrent.*;
public class BurstExecutor {
private final ExecutorService executor;
private final KList<Future<?>> futures;
@Setter
private boolean multicore = true;
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
this.executor = executor;
@@ -46,6 +48,16 @@ public class BurstExecutor {
}
public BurstExecutor queue(List<Runnable> r) {
if(!multicore)
{
for(Runnable i : new KList<>(r))
{
i.run();
}
return this;
}
synchronized (futures) {
for (Runnable i : new KList<>(r)) {
queue(i);
@@ -56,6 +68,16 @@ public class BurstExecutor {
}
public BurstExecutor queue(Runnable[] r) {
if(!multicore)
{
for(Runnable i : new KList<>(r))
{
i.run();
}
return this;
}
synchronized (futures) {
for (Runnable i : r) {
queue(i);
@@ -66,6 +88,11 @@ public class BurstExecutor {
}
public void complete() {
if(!multicore)
{
return;
}
synchronized (futures) {
if (futures.isEmpty()) {
return;
@@ -85,6 +112,11 @@ public class BurstExecutor {
}
public boolean complete(long maxDur) {
if(!multicore)
{
return true;
}
synchronized (futures) {
if (futures.isEmpty()) {
return true;

View File

@@ -72,10 +72,40 @@ public class MultiBurst {
burst(r.length).queue(r).complete();
}
public void burst(boolean multicore, Runnable... r) {
if(multicore)
{
burst(r);
}
else
{
sync(r);
}
}
public void burst(List<Runnable> r) {
burst(r.size()).queue(r).complete();
}
public void burst(boolean multicore, List<Runnable> r) {
if(multicore)
{
burst(r);
}
else {
sync(r);
}
}
private void sync(List<Runnable> r) {
for(Runnable i : new KList<>(r))
{
i.run();
}
}
public void sync(Runnable... r) {
for (Runnable i : r) {
i.run();
@@ -96,6 +126,12 @@ public class MultiBurst {
return burst(16);
}
public BurstExecutor burst(boolean multicore) {
BurstExecutor b = burst();
b.setMulticore(multicore);
return b;
}
public <T> Future<T> lazySubmit(Callable<T> o) {
return getService().submit(o);
}

View File

@@ -129,7 +129,6 @@ public class J {
try {
r.run();
} catch (Throwable e) {
Iris.reportError(e);
return e;
}