Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ See the patches list below.
[PandaSpigot-0112] Fix MC-120567: Bed portal crash
[PandaSpigot-0107] Fix GH-276: Item durability desync when some events are cancelled
[PandaSpigot-0031] Add missing InventoryView.getSlotType API
[PandaSpigot-0104] Backport modern tick loop system

[Spigot-0097] Remove DataWatcher Locking by spottedleaf
[Spigot-0138] Branchless NibbleArray by md5
Expand Down Expand Up @@ -188,7 +189,6 @@ See the patches list below.
[SportPaper-0201] Cache block break animation packet
[SportPaper-0203] Fix Teleport Invisibility
[SportPaper-0204] Optimize toLegacyData removing unneeded sanity checks
[SportPaper-0108] Optimize Network Queue
[SportPaper-0260] Migrate from Trove to fastutil

[PaperBin-????] WorldServer#everyoneDeeplySleeping optimization
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
private boolean s;

// CraftBukkit start - Signature changed
public DedicatedServer(joptsimple.OptionSet options, Thread thread1) { // WindSpigot - backport modern tick loop
super(options, Proxy.NO_PROXY, DedicatedServer.a, thread1);
public DedicatedServer(joptsimple.OptionSet options) {
super(options, Proxy.NO_PROXY, DedicatedServer.a);
// CraftBukkit end
if (!WindSpigotConfig.disableInfiniSleeperThreadUsage) {
Thread thread = new Thread("Server Infinisleeper") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package net.minecraft.server;

import com.google.common.collect.Queues;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Queue;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;

public abstract class IAsyncTaskHandler<R extends Runnable> {

public static final long BLOCK_TIME_NANOS = 100000L;
private static final Logger LOGGER = LogManager.getLogger();
private final String name;
private final Queue<R> pendingTasks = Queues.newConcurrentLinkedQueue();
private int blockingCount;

protected IAsyncTaskHandler(final String name) {
this.name = name;
}

public static boolean isNonRecoverable(final Throwable t) {
return t instanceof ReportedException ? isNonRecoverable(t.getCause()) : t instanceof OutOfMemoryError || t instanceof StackOverflowError;
}

protected abstract R wrapRunnable(final Runnable runnable);

protected abstract boolean shouldRun(final R task);

public boolean isMainThread() {
return Thread.currentThread() == this.aM();
} // Poor name, just to maintain compatibility

protected abstract Thread aM(); // Poor name, just to maintain compatibility

protected boolean scheduleExecutables() {
return !this.isMainThread();
}

public String name() {
return this.name;
}

public void schedule(final R task) {
this.pendingTasks.add(task);
LockSupport.unpark(aM());
}

public void execute(final Runnable command) {
R task = this.wrapRunnable(command);
if (this.scheduleExecutables()) {
this.schedule(task);
} else {
this.doRunTask(task);
}
}

public void postToMainThread(final Runnable runnable) {
execute(runnable);
}

protected void runAllTasks() {
while (this.pollTask()) {
}
}

protected boolean pollTask() {
R task = this.pendingTasks.peek();
if (task == null) {
return false;
} else if (this.blockingCount == 0 && !shouldRun(task)) {
return false;
} else {
this.doRunTask(this.pendingTasks.remove());
return true;
}
}

public void managedBlock(final BooleanSupplier condition) {
this.blockingCount++;

try {
while (!condition.getAsBoolean()) {
if (!this.pollTask()) {
this.waitForTasks();
}
}
} finally {
this.blockingCount--;
}
}

protected void waitForTasks() {
Thread.yield();
LockSupport.parkNanos("waiting for tasks", BLOCK_TIME_NANOS);
}

protected void doRunTask(final R task) {
try {
task.run();
} catch (Exception e) {
LOGGER.fatal("Error executing task on {}", this.name, e);
if (isNonRecoverable(e)) {
throw e;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.minecraft.server;

public abstract class IAsyncTaskHandlerReentrant<R extends Runnable> extends IAsyncTaskHandler<R> {

private int reentrantCount;

public IAsyncTaskHandlerReentrant(final String name) {
super(name);
}

@Override
protected boolean scheduleExecutables() {
return this.runningTask() || super.scheduleExecutables();
}

protected boolean runningTask() {
return this.reentrantCount > 0;
}

@Override
protected void doRunTask(final R task) {
this.reentrantCount++;

try {
super.doRunTask(task);
} finally {
this.reentrantCount--;
}
}
}
Loading
Loading