3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 17:30:08 +01:00

Adjust to using Semaphore

Dieser Commit ist enthalten in:
dordsor21 2024-09-29 14:16:31 +01:00
Ursprung e6481ee6b9
Commit e1bd0639a0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B

Datei anzeigen

@ -74,8 +74,8 @@ import java.io.File;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
/** /**
* An abstract implementation of both a {@link Actor} and a {@link Player} * An abstract implementation of both a {@link Actor} and a {@link Player}
@ -88,7 +88,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
//FAWE start //FAWE start
private final Map<String, Object> meta; private final Map<String, Object> meta;
private final StampedLock clipboardLoading = new StampedLock(); private final Semaphore clipboardLoading = new Semaphore(1);
// Queue for async tasks // Queue for async tasks
private final AtomicInteger runningCount = new AtomicInteger(); private final AtomicInteger runningCount = new AtomicInteger();
@ -544,21 +544,24 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public void loadClipboardFromDisk() { public void loadClipboardFromDisk() {
if (clipboardLoading.isWriteLocked()) { if (!clipboardLoading.tryAcquire()) {
if (!Fawe.isMainThread()) { if (!Fawe.isMainThread()) {
long stamp = clipboardLoading.writeLock(); try {
clipboardLoading.unlockWrite(stamp); clipboardLoading.acquire();
clipboardLoading.release();
} catch (InterruptedException e) {
LOGGER.error("Error waiting for clipboard-on-disk loading for player {}", getName(), e);
}
} }
return; return;
} }
final long stamp = clipboardLoading.writeLock();
File file = MainUtil.getFile( File file = MainUtil.getFile(
Fawe.platform().getDirectory(), Fawe.platform().getDirectory(),
Settings.settings().PATHS.CLIPBOARD + File.separator + getUniqueId() + ".bd" Settings.settings().PATHS.CLIPBOARD + File.separator + getUniqueId() + ".bd"
); );
Future<?> fut = Fawe.instance().submitUUIDKeyQueuedTask(getUniqueId(), () -> { try {
try { Future<?> fut = Fawe.instance().submitUUIDKeyQueuedTask(getUniqueId(), () -> {
try { try {
getSession().loadClipboardFromDisk(file); getSession().loadClipboardFromDisk(file);
} catch (FaweClipboardVersionMismatchException e) { } catch (FaweClipboardVersionMismatchException e) {
@ -577,15 +580,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
print(Caption.of("fawe.error.no-failure")); print(Caption.of("fawe.error.no-failure"));
print(Caption.of("fawe.error.clipboard.invalid.info", file.getName(), file.length())); print(Caption.of("fawe.error.clipboard.invalid.info", file.getName(), file.length()));
print(Caption.of("fawe.error.stacktrace")); print(Caption.of("fawe.error.stacktrace"));
} finally {
clipboardLoading.release();
} }
} finally { });
clipboardLoading.unlockWrite(stamp); if (Fawe.isMainThread()) {
return;
} }
});
if (Fawe.isMainThread()) {
return;
}
try {
fut.get(); fut.get();
} catch (Exception e) { } catch (Exception e) {
print(Caption.of("fawe.error.clipboard.invalid")); print(Caption.of("fawe.error.clipboard.invalid"));