9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-22 08:19:31 +00:00

Yielding ChunkTaskScheduler

This commit is contained in:
Martijn Muijsers
2023-02-05 21:58:32 +01:00
parent 4d37dc3a68
commit 2c62764cce
25 changed files with 539 additions and 248 deletions

View File

@@ -1,57 +0,0 @@
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..5531c681b3547c32f4fc8ec86bb722e1ee653826 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,7 +74,7 @@ public final class PooledObjects<E> {
public final E acquire() {
E value;
- synchronized (queue) {
+ try (var ignored = this.queueLock.withSpinLock()) { // Gale - non-blocking PooledObjects
value = this.queue.pollLast();
}
return value != null ? value : this.creator.get();
@@ -76,7 +84,7 @@ public final class PooledObjects<E> {
if (this.releaser != null) {
this.releaser.accept(value);
}
- synchronized (this.queue) {
+ try (var ignored = this.queueLock.withSpinLock()) { // Gale - non-blocking PooledObjects
if (queue.size() < this.maxPoolSize) {
this.queue.addLast(value);
}