mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 04:51:29 +01:00
Do not use the thread as blocker
This commit is contained in:
parent
156e89e490
commit
997e35459e
@ -44,7 +44,6 @@ public class TickThread extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static class BatchRunnable implements Runnable {
|
protected static class BatchRunnable implements Runnable {
|
||||||
|
|
||||||
private static final AtomicReferenceFieldUpdater<BatchRunnable, TickContext> CONTEXT_UPDATER =
|
private static final AtomicReferenceFieldUpdater<BatchRunnable, TickContext> CONTEXT_UPDATER =
|
||||||
AtomicReferenceFieldUpdater.newUpdater(BatchRunnable.class, TickContext.class, "tickContext");
|
AtomicReferenceFieldUpdater.newUpdater(BatchRunnable.class, TickContext.class, "tickContext");
|
||||||
|
|
||||||
@ -57,20 +56,15 @@ public class TickThread extends Thread {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Check.notNull(tickThread, "The linked BatchThread cannot be null!");
|
Check.notNull(tickThread, "The linked BatchThread cannot be null!");
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
LockSupport.park(tickThread);
|
final TickContext localContext = tickContext;
|
||||||
if (stop)
|
|
||||||
break;
|
|
||||||
TickContext localContext = tickContext;
|
|
||||||
// The context is necessary to control the tick rates
|
// The context is necessary to control the tick rates
|
||||||
if (localContext == null) {
|
if (localContext != null) {
|
||||||
continue;
|
// Execute tick
|
||||||
|
localContext.runnable.run();
|
||||||
|
localContext.countDownLatch.countDown();
|
||||||
|
CONTEXT_UPDATER.compareAndSet(this, localContext, null);
|
||||||
}
|
}
|
||||||
|
LockSupport.park(this);
|
||||||
// Execute tick
|
|
||||||
localContext.runnable.run();
|
|
||||||
|
|
||||||
localContext.countDownLatch.countDown();
|
|
||||||
CONTEXT_UPDATER.compareAndSet(this, localContext, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,5 +87,4 @@ public class TickThread extends Thread {
|
|||||||
this.runnable = runnable;
|
this.runnable = runnable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user