mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-05 23:36:12 +00:00
Compiling
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.scheduling.jobs;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
|
||||
public abstract class ParallelQueueJob<T> extends QueueJob<T> {
|
||||
@Override
|
||||
public void execute() {
|
||||
while (queue.isNotEmpty()) {
|
||||
BurstExecutor b = MultiBurst.burst.burst(queue.size());
|
||||
KList<T> q = queue.copy();
|
||||
queue.clear();
|
||||
for(T i : q)
|
||||
{
|
||||
b.queue(() -> {
|
||||
execute(i);
|
||||
completeWork();
|
||||
});
|
||||
}
|
||||
b.complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,27 +18,32 @@
|
||||
|
||||
package com.volmit.iris.util.scheduling.jobs;
|
||||
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class QueueJob<T> implements Job {
|
||||
private final KList<T> queue;
|
||||
private int totalWork;
|
||||
private int completed;
|
||||
final KList<T> queue;
|
||||
protected int totalWork;
|
||||
private AtomicInteger completed;
|
||||
|
||||
public QueueJob() {
|
||||
totalWork = 0;
|
||||
completed = 0;
|
||||
completed = new AtomicInteger(0);
|
||||
queue = new KList<>();
|
||||
}
|
||||
|
||||
public void queue(T t) {
|
||||
public QueueJob queue(T t) {
|
||||
queue.add(t);
|
||||
totalWork++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void queue(KList<T> f) {
|
||||
public QueueJob queue(KList<T> f) {
|
||||
queue.addAll(f);
|
||||
totalWork += f.size();
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract void execute(T t);
|
||||
@@ -54,7 +59,7 @@ public abstract class QueueJob<T> implements Job {
|
||||
|
||||
@Override
|
||||
public void completeWork() {
|
||||
completed++;
|
||||
completed.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +69,6 @@ public abstract class QueueJob<T> implements Job {
|
||||
|
||||
@Override
|
||||
public int getWorkCompleted() {
|
||||
return completed;
|
||||
return completed.get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user