From 75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed Mon Sep 17 00:00:00 2001 From: AgentLV Date: Sat, 10 Sep 2016 23:09:29 +0200 Subject: Run sync tasks scheduled for the same tick FIFO --- src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index 9fea4fb3..bdddf0b5 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -32,7 +32,7 @@ import org.bukkit.scheduler.BukkitWorker; *
  • Changing the period on a task is delicate. * Any future task needs to notify waiting threads. * Async tasks must be synchronized to make sure that any thread that's finishing will remove itself from {@link #runners}. - * Another utility method is provided for this, {@link #cancelTask(CraftTask)}
  • + * Another utility method is provided for this, {@link #cancelTask(int)} *
  • {@link #runners} provides a moderately up-to-date view of active tasks. * If the linked head to tail set is read, all remaining tasks that were active at the time execution started will be located in runners.
  • *
  • Async tasks are responsible for removing themselves from runners
  • @@ -60,7 +60,10 @@ public class CraftScheduler implements BukkitScheduler { private final PriorityQueue pending = new PriorityQueue(10, new Comparator() { public int compare(final CraftTask o1, final CraftTask o2) { - return (int) (o1.getNextRun() - o2.getNextRun()); + int value = (int) (o1.getNextRun() - o2.getNextRun()); + + // If the tasks should run on the same tick they should be run FIFO + return value != 0 ? value : o1.getTaskId() - o2.getTaskId(); } }); /** -- cgit v1.2.3