106 lines
4.2 KiB
Diff
106 lines
4.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Simon Gardling <titaniumtown@gmail.com>
|
|
Date: Thu, 8 Jul 2021 17:03:31 -0400
|
|
Subject: [PATCH] Use MCUtil.asyncExecutor for MAIN_WORKER_EXECUTOR in
|
|
SystemUtils
|
|
|
|
Original code by Titaniumtown, licensed under GNU General Public License v3.0
|
|
You can find the original code on https://gitlab.com/Titaniumtown/JettPack
|
|
|
|
diff --git a/src/main/java/me/titaniumtown/ServerWorkerWrapper.java b/src/main/java/me/titaniumtown/ServerWorkerWrapper.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..7bd88761137b2a68c04fbaa920a9ea9ce1f9e873
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/titaniumtown/ServerWorkerWrapper.java
|
|
@@ -0,0 +1,24 @@
|
|
+package me.titaniumtown;
|
|
+
|
|
+import com.google.common.base.Preconditions;
|
|
+import net.minecraft.Util;
|
|
+
|
|
+public final class ServerWorkerWrapper implements Runnable {
|
|
+ private final Runnable internalRunnable;
|
|
+
|
|
+ public ServerWorkerWrapper(Runnable runnable) {
|
|
+ this.internalRunnable = Preconditions.checkNotNull(runnable, "internalRunnable");
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final void run() {
|
|
+ try {
|
|
+ this.internalRunnable.run();
|
|
+ return;
|
|
+ }
|
|
+ catch (Throwable throwable) {
|
|
+ Util.onThreadException(Thread.currentThread(), throwable);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
|
|
index 59ecf5ff33617a6b9d2a3ae317315484235da804..4b4f3533f6f8624551794e63baae87138a495835 100644
|
|
--- a/src/main/java/net/minecraft/Util.java
|
|
+++ b/src/main/java/net/minecraft/Util.java
|
|
@@ -73,6 +73,12 @@ import net.minecraft.util.TimeSource;
|
|
import net.minecraft.util.datafix.DataFixers;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import org.slf4j.Logger;
|
|
+// JettPack start
|
|
+import java.util.concurrent.AbstractExecutorService;
|
|
+import me.titaniumtown.ServerWorkerWrapper;
|
|
+import net.minecraft.server.MCUtil;
|
|
+import java.util.Collections;
|
|
+// JettPack end
|
|
|
|
public class Util {
|
|
static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -165,7 +171,46 @@ public class Util {
|
|
if (i <= 0) {
|
|
executorService = MoreExecutors.newDirectExecutorService();
|
|
} else {
|
|
- executorService = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue<Runnable>(), target -> new net.minecraft.server.ServerWorkerThread(target, s, priorityModifier));
|
|
+ //executorService = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue<Runnable>(), target -> new net.minecraft.server.ServerWorkerThread(target, s, priorityModifier)); // JettPack
|
|
+ // JettPack start
|
|
+ executorService = Integer.getInteger("Paper.WorkerThreadCount", i) <= 0 ? MoreExecutors.newDirectExecutorService() : new AbstractExecutorService(){
|
|
+ private volatile boolean shutdown = false;
|
|
+
|
|
+ @Override
|
|
+ public final List<Runnable> shutdownNow() {
|
|
+ this.shutdown = true;
|
|
+ return Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final void shutdown() {
|
|
+ this.shutdown = true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final boolean isShutdown() {
|
|
+ return this.shutdown;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final boolean isTerminated() {
|
|
+ return this.shutdown;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final boolean awaitTermination(long l2, TimeUnit timeUnit) throws InterruptedException {
|
|
+ if (!this.shutdown) {
|
|
+ throw new UnsupportedOperationException();
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final void execute(Runnable runnable) {
|
|
+ MCUtil.asyncExecutor.execute(new ServerWorkerWrapper(runnable));
|
|
+ }
|
|
+ };
|
|
+ // JettPack end
|
|
}
|
|
/*
|
|
@Override
|