mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-05 06:32:17 -07:00
Move patches to unapplied
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
--- a/net/minecraft/util/TickThrottler.java
|
||||
+++ b/net/minecraft/util/TickThrottler.java
|
||||
@@ -1,10 +1,14 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.concurrent.atomic.AtomicInteger;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class TickThrottler {
|
||||
|
||||
private final int incrementStep;
|
||||
private final int threshold;
|
||||
- private int count;
|
||||
+ private final AtomicInteger count = new AtomicInteger(); // CraftBukkit - multithreaded field
|
||||
|
||||
public TickThrottler(int increment, int threshold) {
|
||||
this.incrementStep = increment;
|
||||
@@ -12,17 +16,32 @@
|
||||
}
|
||||
|
||||
public void increment() {
|
||||
- this.count += this.incrementStep;
|
||||
+ this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
+ // CraftBukkit start
|
||||
+ for (int val; (val = this.count.get()) > 0 && !this.count.compareAndSet(val, val - 1); ) ;
|
||||
+ /* Use thread-safe field access instead
|
||||
if (this.count > 0) {
|
||||
--this.count;
|
||||
}
|
||||
+ */
|
||||
+ // CraftBukkit end
|
||||
|
||||
}
|
||||
|
||||
public boolean isUnderThreshold() {
|
||||
- return this.count < this.threshold;
|
||||
+ // CraftBukkit start - use thread-safe field access instead
|
||||
+ return this.count.get() < this.threshold;
|
||||
}
|
||||
+
|
||||
+ public boolean isIncrementAndUnderThreshold() {
|
||||
+ return this.isIncrementAndUnderThreshold(this.incrementStep, this.threshold);
|
||||
+ }
|
||||
+
|
||||
+ public boolean isIncrementAndUnderThreshold(int incrementStep, int threshold) {
|
||||
+ return this.count.addAndGet(incrementStep) < threshold;
|
||||
+ // CraftBukkit end
|
||||
+ }
|
||||
}
|
Reference in New Issue
Block a user