mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-03 14:01:58 +01:00
Reduce monitor acquisition
This commit is contained in:
parent
a6b1749e9e
commit
44b22ce1f1
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.thread;
|
package net.minestom.server.thread;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.Monitor;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.instance.Chunk;
|
import net.minestom.server.instance.Chunk;
|
||||||
@ -144,17 +145,24 @@ public abstract class ThreadProvider {
|
|||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
Acquirable.refreshEntities(Collections.unmodifiableList(entities));
|
Acquirable.refreshEntities(Collections.unmodifiableList(entities));
|
||||||
|
|
||||||
|
final Monitor monitor = thread.monitor;
|
||||||
|
monitor.enter();
|
||||||
chunkEntries.forEach(chunkEntry -> {
|
chunkEntries.forEach(chunkEntry -> {
|
||||||
Chunk chunk = chunkEntry.chunk;
|
Chunk chunk = chunkEntry.chunk;
|
||||||
if (!ChunkUtils.isLoaded(chunk))
|
if (!ChunkUtils.isLoaded(chunk))
|
||||||
return;
|
return;
|
||||||
chunk.tick(time);
|
chunk.tick(time);
|
||||||
chunkEntry.entities.forEach(entity -> {
|
chunkEntry.entities.forEach(entity -> {
|
||||||
thread.monitor.enter();
|
final boolean hasQueue = monitor.hasQueuedThreads();
|
||||||
|
if (hasQueue) {
|
||||||
|
monitor.leave();
|
||||||
|
monitor.enter();
|
||||||
|
}
|
||||||
entity.tick(time);
|
entity.tick(time);
|
||||||
thread.monitor.leave();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
monitor.leave();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return countDownLatch;
|
return countDownLatch;
|
||||||
|
Loading…
Reference in New Issue
Block a user