mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Only unlock if previously locked (#2489)
This commit is contained in:
parent
1996a38b46
commit
46dd71e807
@ -100,7 +100,6 @@ import java.util.TimeZone;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -406,7 +405,8 @@ public class LocalSession implements TextureHolder {
|
|||||||
*/
|
*/
|
||||||
public void clearHistory() {
|
public void clearHistory() {
|
||||||
//FAWE start
|
//FAWE start
|
||||||
if (Fawe.isMainThread() && !historyWriteLock.tryLock()) {
|
boolean mainThread = Fawe.isMainThread();
|
||||||
|
if (mainThread && !historyWriteLock.tryLock()) {
|
||||||
// Do not make main thread wait if we cannot immediately clear history (on player logout usually)
|
// Do not make main thread wait if we cannot immediately clear history (on player logout usually)
|
||||||
TaskManager.taskManager().async(this::clearHistoryTask);
|
TaskManager.taskManager().async(this::clearHistoryTask);
|
||||||
return;
|
return;
|
||||||
@ -414,9 +414,12 @@ public class LocalSession implements TextureHolder {
|
|||||||
try {
|
try {
|
||||||
clearHistoryTask();
|
clearHistoryTask();
|
||||||
} finally {
|
} finally {
|
||||||
|
// only if we are on the main thread, we ever called tryLock -> need to unlock again
|
||||||
|
if (mainThread) {
|
||||||
historyWriteLock.unlock();
|
historyWriteLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void clearHistoryTask() {
|
private void clearHistoryTask() {
|
||||||
historyWriteLock.lock();
|
historyWriteLock.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user