summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAgentLV <contact@agentlv.net>2016-09-10 23:09:29 +0200
committermd_5 <git@md-5.net>2016-09-11 15:03:27 +1000
commit75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed (patch)
tree43389ee68dd350b4fbaf84cba0fa40a2be7d22b5 /src
parentbae15259ed1a53e2ea52b001288f82c24fd8497c (diff)
downloadcraftbukkit-75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed.tar
craftbukkit-75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed.tar.gz
craftbukkit-75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed.tar.lz
craftbukkit-75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed.tar.xz
craftbukkit-75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed.zip
Run sync tasks scheduled for the same tick FIFO
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java7
1 files changed, 5 insertions, 2 deletions
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;
* <li>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)}</li>
+ * Another utility method is provided for this, {@link #cancelTask(int)}</li>
* <li>{@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.</li>
* <li>Async tasks are responsible for removing themselves from runners</li>
@@ -60,7 +60,10 @@ public class CraftScheduler implements BukkitScheduler {
private final PriorityQueue<CraftTask> pending = new PriorityQueue<CraftTask>(10,
new Comparator<CraftTask>() {
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();
}
});
/**