mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-25 01:25:03 +01:00
SPIGOT-3619: Improve CraftScheduler#isCurrentlyRunning
* No longer returns opposite of what it should * Works for sync tasks as well By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
parent
2fff732946
commit
0e8e610b0e
1 changed files with 12 additions and 2 deletions
|
@ -74,6 +74,10 @@ public class CraftScheduler implements BukkitScheduler {
|
||||||
* These are tasks that are currently active. It's provided for 'viewing' the current state.
|
* 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>();
|
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 volatile int currentTick = -1;
|
||||||
private final Executor executor = Executors.newCachedThreadPool();
|
private final Executor executor = Executors.newCachedThreadPool();
|
||||||
private CraftAsyncDebugger debugHead = new CraftAsyncDebugger(-1, null, null) {@Override StringBuilder debugTo(StringBuilder string) {return string;}};
|
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) {
|
public boolean isCurrentlyRunning(final int taskId) {
|
||||||
final CraftTask task = runners.get(taskId);
|
final CraftTask task = runners.get(taskId);
|
||||||
if (task == null || task.isSync()) {
|
if (task == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (task.isSync()) {
|
||||||
|
return (task == currentTask);
|
||||||
|
}
|
||||||
final CraftAsyncTask asyncTask = (CraftAsyncTask) task;
|
final CraftAsyncTask asyncTask = (CraftAsyncTask) task;
|
||||||
synchronized (asyncTask.getWorkers()) {
|
synchronized (asyncTask.getWorkers()) {
|
||||||
return asyncTask.getWorkers().isEmpty();
|
return !asyncTask.getWorkers().isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,6 +355,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (task.isSync()) {
|
if (task.isSync()) {
|
||||||
|
currentTask = task;
|
||||||
try {
|
try {
|
||||||
task.run();
|
task.run();
|
||||||
} catch (final Throwable throwable) {
|
} catch (final Throwable throwable) {
|
||||||
|
@ -358,6 +366,8 @@ public class CraftScheduler implements BukkitScheduler {
|
||||||
task.getTaskId(),
|
task.getTaskId(),
|
||||||
task.getOwner().getDescription().getFullName()),
|
task.getOwner().getDescription().getFullName()),
|
||||||
throwable);
|
throwable);
|
||||||
|
} finally {
|
||||||
|
currentTask = null;
|
||||||
}
|
}
|
||||||
parsePending();
|
parsePending();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue