mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-20 01:25:27 +01:00
hollow-cube/tick-thread-counter
Signed-off-by: mworzala <mattheworzala@gmail.com>
Add a tick counter in the current tick thread and a way to get the current tick thread.
(cherry picked from commit 65ff64658efef55ac04053dc653fff492cc38a55)
(cherry picked from commit 72a456eea8
)
This commit is contained in:
parent
2cdb3911b0
commit
dd146dab41
@ -6,6 +6,7 @@ import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -26,12 +27,19 @@ public final class TickThread extends MinestomThread {
|
||||
|
||||
private CountDownLatch latch;
|
||||
private long tickTime;
|
||||
private long tickNum = 0;
|
||||
private final List<ThreadDispatcher.Partition> entries = new ArrayList<>();
|
||||
|
||||
public TickThread(int number) {
|
||||
super(MinecraftServer.THREAD_NAME_TICK + "-" + number);
|
||||
}
|
||||
|
||||
public static @Nullable TickThread current() {
|
||||
if (Thread.currentThread() instanceof TickThread current)
|
||||
return current;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LockSupport.park(this);
|
||||
@ -79,6 +87,7 @@ public final class TickThread extends MinestomThread {
|
||||
}
|
||||
this.latch = latch;
|
||||
this.tickTime = tickTime;
|
||||
this.tickNum += 1;
|
||||
this.stop = false;
|
||||
LockSupport.unpark(this);
|
||||
}
|
||||
@ -96,6 +105,10 @@ public final class TickThread extends MinestomThread {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public long getTick() {
|
||||
return tickNum;
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
this.stop = true;
|
||||
LockSupport.unpark(this);
|
||||
|
Loading…
Reference in New Issue
Block a user