diff options
author | blablubbabc <lukas@wirsindwir.de> | 2018-06-17 15:04:25 +0200 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-06-20 13:11:50 +1000 |
commit | fbe3046435815a1423bf4a287ad9ec914c91bb55 (patch) | |
tree | f5a019a0ac7f6a26f1b332a60722f1da884a6770 /src/main | |
parent | 2f3ed3b2d01adc01e15a5cf83929ae2a40ddccf2 (diff) | |
download | craftbukkit-fbe3046435815a1423bf4a287ad9ec914c91bb55.tar craftbukkit-fbe3046435815a1423bf4a287ad9ec914c91bb55.tar.gz craftbukkit-fbe3046435815a1423bf4a287ad9ec914c91bb55.tar.lz craftbukkit-fbe3046435815a1423bf4a287ad9ec914c91bb55.tar.xz craftbukkit-fbe3046435815a1423bf4a287ad9ec914c91bb55.zip |
SPIGOT-3619: Improve CraftScheduler#isCurrentlyRunning
* No longer returns opposite of what it should
* Works for sync tasks as well
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java | 14 |
1 files changed, 12 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 96eff377..7b4dab91 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -74,6 +74,10 @@ public class CraftScheduler implements BukkitScheduler { * These are tasks that are currently active. It's provided for 'viewing' the current state. */ private final ConcurrentHashMap<Integer, CraftTask> runners = new ConcurrentHashMap<Integer, CraftTask>(); + /** + * The sync task that is currently running on the main thread. + */ + private volatile CraftTask currentTask = null; private volatile int currentTick = -1; private final Executor executor = Executors.newCachedThreadPool(); private CraftAsyncDebugger debugHead = new CraftAsyncDebugger(-1, null, null) {@Override StringBuilder debugTo(StringBuilder string) {return string;}}; @@ -269,12 +273,15 @@ public class CraftScheduler implements BukkitScheduler { public boolean isCurrentlyRunning(final int taskId) { final CraftTask task = runners.get(taskId); - if (task == null || task.isSync()) { + if (task == null) { return false; } + if (task.isSync()) { + return (task == currentTask); + } final CraftAsyncTask asyncTask = (CraftAsyncTask) task; synchronized (asyncTask.getWorkers()) { - return asyncTask.getWorkers().isEmpty(); + return !asyncTask.getWorkers().isEmpty(); } } @@ -348,6 +355,7 @@ public class CraftScheduler implements BukkitScheduler { continue; } if (task.isSync()) { + currentTask = task; try { task.run(); } catch (final Throwable throwable) { @@ -358,6 +366,8 @@ public class CraftScheduler implements BukkitScheduler { task.getTaskId(), task.getOwner().getDescription().getFullName()), throwable); + } finally { + currentTask = null; } parsePending(); } else { |