Skip to content

Commit

Permalink
Only unlock if previously locked (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell authored Nov 8, 2023
1 parent 1996a38 commit 46dd71e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -406,15 +405,19 @@ public void setTimezone(ZoneId timezone) {
*/
public void clearHistory() {
//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)
TaskManager.taskManager().async(this::clearHistoryTask);
return;
}
try {
clearHistoryTask();
} finally {
historyWriteLock.unlock();
// only if we are on the main thread, we ever called tryLock -> need to unlock again
if (mainThread) {
historyWriteLock.unlock();
}
}
}

Expand Down

0 comments on commit 46dd71e

Please sign in to comment.