@@ -1,11 +1,11 @@
|
||||
package org.bukkit.craftbukkit.scheduler;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
public class CraftFuture<T> implements Runnable, Future<T> {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class CraftFuture<T> implements Runnable, Future<T> {
|
||||
private Exception e = null;
|
||||
private int taskId = -1;
|
||||
|
||||
CraftFuture(CraftScheduler craftScheduler, Callable callable) {
|
||||
CraftFuture(CraftScheduler craftScheduler, Callable<T> callable) {
|
||||
this.callable = callable;
|
||||
this.craftScheduler = craftScheduler;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,26 @@
|
||||
package org.bukkit.craftbukkit.scheduler;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitWorker;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.scheduler.CraftTask;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.scheduler.BukkitWorker;
|
||||
|
||||
public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
private final CraftServer server;
|
||||
|
||||
private final CraftThreadManager craftThreadManager = new CraftThreadManager();
|
||||
|
||||
private final LinkedList<CraftTask> mainThreadQueue = new LinkedList<CraftTask>();
|
||||
@@ -35,13 +28,17 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
|
||||
private final TreeMap<CraftTask, Boolean> schedulerQueue = new TreeMap<CraftTask, Boolean>();
|
||||
|
||||
private final Object currentTickSync = new Object();
|
||||
private Long currentTick = 0L;
|
||||
|
||||
// This lock locks the mainThreadQueue and the currentTick value
|
||||
private final Lock mainThreadLock = new ReentrantLock();
|
||||
private final Lock syncedTasksLock = new ReentrantLock();
|
||||
|
||||
public CraftScheduler() {
|
||||
Thread t = new Thread(this);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
@@ -108,14 +105,6 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public CraftScheduler(CraftServer server) {
|
||||
this.server = server;
|
||||
|
||||
Thread t = new Thread(this);
|
||||
t.start();
|
||||
|
||||
}
|
||||
|
||||
// If the main thread cannot obtain the lock, it doesn't wait
|
||||
public void mainThreadHeartbeat(long currentTick) {
|
||||
if (syncedTasksLock.tryLock()) {
|
||||
|
||||
Reference in New Issue
Block a user