mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-26 18:19:11 +00:00
Separate cleaner task queue
This commit is contained in:
@@ -130,7 +130,7 @@ index 3088d5f008a8cb5a75f1e11bd80a2614a4c1b75d..0c771f024cec0b3fbb68e4eeeeb77818
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
index 1e812c4f5a8d54293084de29e8731e0b8ddcc0ae..31699c5b9f186ff91ee2c0da092212e85ef35c79 100644
|
||||
index 1e812c4f5a8d54293084de29e8731e0b8ddcc0ae..ab870c98210d6654230335db5c8ff6739bb2357f 100644
|
||||
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
@@ -2,12 +2,10 @@ package io.papermc.paper.util;
|
||||
@@ -206,7 +206,7 @@ index 1e812c4f5a8d54293084de29e8731e0b8ddcc0ae..31699c5b9f186ff91ee2c0da092212e8
|
||||
- .build()
|
||||
- );
|
||||
+ public static final Executor asyncExecutor = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pools - remove Paper async executor
|
||||
+ public static final Executor cleanerExecutor = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pools - remove Paper cleaner executor
|
||||
+ public static final Executor cleanerExecutor = BaseTaskQueues.cleaner.executor; // Gale - base thread pools - remove Paper cleaner executor
|
||||
|
||||
public static final long INVALID_CHUNK_KEY = getCoordinateKey(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
@@ -3175,14 +3175,15 @@ index 0000000000000000000000000000000000000000..a4117d2e677617bd8fcbb15f59fdec9a
|
||||
+}
|
||||
diff --git a/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueues.java b/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueues.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..1b91ba1e7fef0516638dd952f3ec74dff533cc44
|
||||
index 0000000000000000000000000000000000000000..286b893749db38afc49fd03a0ac006598268d26e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueues.java
|
||||
@@ -0,0 +1,109 @@
|
||||
@@ -0,0 +1,115 @@
|
||||
+// Gale - base thread pools
|
||||
+
|
||||
+package org.galemc.gale.executor.queue;
|
||||
+
|
||||
+import io.papermc.paper.util.MCUtil;
|
||||
+import io.papermc.paper.util.TickThread;
|
||||
+import org.galemc.gale.executor.thread.pooled.TickAssistThread;
|
||||
+import org.galemc.gale.executor.thread.deferral.TickThreadDeferral;
|
||||
@@ -3280,6 +3281,11 @@ index 0000000000000000000000000000000000000000..1b91ba1e7fef0516638dd952f3ec74df
|
||||
+ public static final AllLevelsScheduledTickThreadChunkTaskQueue allLevelsScheduledTickThreadChunk = new AllLevelsScheduledTickThreadChunkTaskQueue();
|
||||
+
|
||||
+ /**
|
||||
+ * This queue stores the tasks posted to {@link MCUtil#cleanerExecutor}.
|
||||
+ */
|
||||
+ public static final FreeSimpleTaskQueue cleaner = new FreeSimpleTaskQueue("Cleaner");
|
||||
+
|
||||
+ /**
|
||||
+ * This queue stores the tasks scheduled to be executed on any thread, which would usually be stored in various
|
||||
+ * executors with a specific purpose.
|
||||
+ * <br>
|
||||
@@ -5236,10 +5242,10 @@ index 0000000000000000000000000000000000000000..0c625b09df52e3dcd61773af53ccfaf3
|
||||
+}
|
||||
diff --git a/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java b/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e222b367053da90323ded78b2939a7bd2af1da2a
|
||||
index 0000000000000000000000000000000000000000..b86516e034c920f1c551764cd5cc2cc338ce5535
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java
|
||||
@@ -0,0 +1,64 @@
|
||||
@@ -0,0 +1,66 @@
|
||||
+// Gale - base thread pools
|
||||
+
|
||||
+package org.galemc.gale.executor.thread.pooled;
|
||||
@@ -5284,6 +5290,8 @@ index 0000000000000000000000000000000000000000..e222b367053da90323ded78b2939a7bd
|
||||
+
|
||||
+ private AsyncThreadPool() {
|
||||
+ super(new AsyncThread[0], "Base Async Thread", new AbstractTaskQueue[] {
|
||||
+ // The cleaner queue has high priority because it releases resources back to a pool, thereby saving memory
|
||||
+ BaseTaskQueues.cleaner,
|
||||
+ BaseTaskQueues.scheduledAsync
|
||||
+ }, MAXIMUM_YIELD_DEPTH);
|
||||
+ }
|
||||
|
||||
77
patches/server/0117-Non-blocking-PooledObjects.patch
Normal file
77
patches/server/0117-Non-blocking-PooledObjects.patch
Normal file
@@ -0,0 +1,77 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
||||
Date: Thu, 22 Dec 2022 16:14:50 +0100
|
||||
Subject: [PATCH] Non-blocking PooledObjects
|
||||
|
||||
License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
|
||||
Gale - https://galemc.org
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/util/pooled/PooledObjects.java b/src/main/java/com/destroystokyo/paper/util/pooled/PooledObjects.java
|
||||
index a743703502cea333bd4231b6557de50e8eaf81eb..0566757ed94cb2c41ace660ef71c8f99b0335032 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/util/pooled/PooledObjects.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/util/pooled/PooledObjects.java
|
||||
@@ -2,11 +2,18 @@ package com.destroystokyo.paper.util.pooled;
|
||||
|
||||
import io.papermc.paper.util.MCUtil;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
+import org.galemc.gale.concurrent.Mutex;
|
||||
+import org.galemc.gale.executor.annotation.YieldFree;
|
||||
+import org.galemc.gale.executor.annotation.thread.AnyThreadSafe;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
+// Gale start - non-blocking PooledObjects
|
||||
+@AnyThreadSafe
|
||||
+@YieldFree
|
||||
+// Gale end - non-blocking PooledObjects
|
||||
public final class PooledObjects<E> {
|
||||
|
||||
/**
|
||||
@@ -36,6 +43,7 @@ public final class PooledObjects<E> {
|
||||
private final Consumer<E> releaser;
|
||||
private final int maxPoolSize;
|
||||
private final ArrayDeque<E> queue;
|
||||
+ private final Mutex queueLock = Mutex.create(); // Gale - non-blocking PooledObjects
|
||||
|
||||
public PooledObjects(final Supplier<E> creator, int maxPoolSize) {
|
||||
this(creator, maxPoolSize, null);
|
||||
@@ -66,8 +74,16 @@ public final class PooledObjects<E> {
|
||||
|
||||
public final E acquire() {
|
||||
E value;
|
||||
- synchronized (queue) {
|
||||
+ // Gale start - non-blocking PooledObjects
|
||||
+ //noinspection StatementWithEmptyBody
|
||||
+ while (!this.queueLock.tryAcquire());
|
||||
+ try {
|
||||
+ // Gale end - non-blocking PooledObjects
|
||||
value = this.queue.pollLast();
|
||||
+ // Gale start - non-blocking PooledObjects
|
||||
+ } finally {
|
||||
+ this.queueLock.release();
|
||||
+ // Gale end - non-blocking PooledObjects
|
||||
}
|
||||
return value != null ? value : this.creator.get();
|
||||
}
|
||||
@@ -76,10 +92,18 @@ public final class PooledObjects<E> {
|
||||
if (this.releaser != null) {
|
||||
this.releaser.accept(value);
|
||||
}
|
||||
- synchronized (this.queue) {
|
||||
+ // Gale start - non-blocking PooledObjects
|
||||
+ //noinspection StatementWithEmptyBody
|
||||
+ while (!this.queueLock.tryAcquire());
|
||||
+ try {
|
||||
+ // Gale end - non-blocking PooledObjects
|
||||
if (queue.size() < this.maxPoolSize) {
|
||||
this.queue.addLast(value);
|
||||
}
|
||||
+ // Gale start - non-blocking PooledObjects
|
||||
+ } finally {
|
||||
+ this.queueLock.release();
|
||||
+ // Gale end - non-blocking PooledObjects
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user