mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 00:17:58 +01:00
Remove unnecessary volatile, fix acquisition from threads other than the tick ones
This commit is contained in:
parent
321d185ffe
commit
d8e28ad73a
@ -90,18 +90,22 @@ public final class Acquisition {
|
||||
time = System.nanoTime();
|
||||
}
|
||||
|
||||
BatchThread current = (BatchThread) currentThread;
|
||||
ReentrantLock currentLock = current.lock;
|
||||
final boolean currentAcquired = currentLock.isHeldByCurrentThread();
|
||||
if (currentAcquired)
|
||||
ReentrantLock currentLock;
|
||||
{
|
||||
final BatchThread current = currentThread instanceof BatchThread ?
|
||||
(BatchThread) currentThread : null;
|
||||
currentLock = current != null && current.getLock().isHeldByCurrentThread() ?
|
||||
current.getLock() : null;
|
||||
}
|
||||
if (currentLock != null)
|
||||
currentLock.unlock();
|
||||
|
||||
GLOBAL_LOCK.lock();
|
||||
|
||||
if (currentAcquired)
|
||||
if (currentLock != null)
|
||||
currentLock.lock();
|
||||
|
||||
final var lock = elementThread != null ? elementThread.lock : null;
|
||||
final var lock = elementThread != null ? elementThread.getLock() : null;
|
||||
final boolean acquired = lock == null || lock.isHeldByCurrentThread();
|
||||
if (!acquired) {
|
||||
lock.lock();
|
||||
|
@ -14,8 +14,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class BatchThread extends Thread {
|
||||
|
||||
private final BatchRunnable runnable;
|
||||
|
||||
public volatile ReentrantLock lock = new ReentrantLock();
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public BatchThread(@NotNull BatchRunnable runnable, int number) {
|
||||
super(runnable, MinecraftServer.THREAD_NAME_TICK + "-" + number);
|
||||
@ -24,11 +23,14 @@ public class BatchThread extends Thread {
|
||||
this.runnable.setLinkedThread(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BatchRunnable getMainRunnable() {
|
||||
public @NotNull BatchRunnable getMainRunnable() {
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public @NotNull ReentrantLock getLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.runnable.stop = true;
|
||||
LockSupport.unpark(this);
|
||||
|
@ -146,7 +146,7 @@ public abstract class ThreadProvider {
|
||||
.collect(Collectors.toList());
|
||||
Acquirable.refreshEntities(Collections.unmodifiableList(entities));
|
||||
|
||||
final ReentrantLock lock = thread.lock;
|
||||
final ReentrantLock lock = thread.getLock();
|
||||
lock.lock();
|
||||
chunkEntries.forEach(chunkEntry -> {
|
||||
Chunk chunk = chunkEntry.chunk;
|
||||
|
Loading…
Reference in New Issue
Block a user