3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 02:50:05 +01:00

accessing clipboards should not be synchronized to LocalSession (#653)

* accessing clipboards should not be synchronized to LocalSession
I believe this may be the issue causing thread locks when wrapping new players. If we're attempting to run a synchronised method within the LocalSesison when initialising it, it may go wrong..?

* nullcheck within synchronisation
Dieser Commit ist enthalten in:
dordsor21 2020-09-25 15:02:09 +01:00 committet von GitHub
Ursprung 855389c785
Commit 65747bf8f8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -134,6 +134,7 @@ public class LocalSession implements TextureHolder {
}); });
private transient volatile Integer historyNegativeIndex; private transient volatile Integer historyNegativeIndex;
private transient ClipboardHolder clipboard; private transient ClipboardHolder clipboard;
private transient final Object clipboardLock = new Object();
private transient boolean superPickaxe = false; private transient boolean superPickaxe = false;
private transient BlockTool pickaxeMode = new SinglePickaxe(); private transient BlockTool pickaxeMode = new SinglePickaxe();
private transient final Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0); private transient final Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
@ -767,19 +768,26 @@ public class LocalSession implements TextureHolder {
* @return clipboard * @return clipboard
* @throws EmptyClipboardException thrown if no clipboard is set * @throws EmptyClipboardException thrown if no clipboard is set
*/ */
public synchronized ClipboardHolder getClipboard() throws EmptyClipboardException { public ClipboardHolder getClipboard() throws EmptyClipboardException {
synchronized (clipboardLock) {
if (clipboard == null) { if (clipboard == null) {
throw new EmptyClipboardException(); throw new EmptyClipboardException();
} }
return clipboard; return clipboard;
} }
@Nullable
public synchronized ClipboardHolder getExistingClipboard() {
return clipboard;
} }
public synchronized void addClipboard(@Nonnull MultiClipboardHolder toAppend) { @Nullable
public ClipboardHolder getExistingClipboard() {
synchronized (clipboardLock) {
if (clipboard == null) {
return null;
}
return clipboard;
}
}
public void addClipboard(@Nonnull MultiClipboardHolder toAppend) {
checkNotNull(toAppend); checkNotNull(toAppend);
ClipboardHolder existing = getExistingClipboard(); ClipboardHolder existing = getExistingClipboard();
MultiClipboardHolder multi; MultiClipboardHolder multi;
@ -804,8 +812,10 @@ public class LocalSession implements TextureHolder {
* *
* @param clipboard the clipboard, or null if the clipboard is to be cleared * @param clipboard the clipboard, or null if the clipboard is to be cleared
*/ */
public synchronized void setClipboard(@Nullable ClipboardHolder clipboard) { public void setClipboard(@Nullable ClipboardHolder clipboard) {
if (this.clipboard == clipboard) return; synchronized (clipboardLock) {
if (this.clipboard == clipboard)
return;
if (this.clipboard != null) { if (this.clipboard != null) {
if (clipboard == null || !clipboard.contains(this.clipboard.getClipboard())) { if (clipboard == null || !clipboard.contains(this.clipboard.getClipboard())) {
@ -814,6 +824,7 @@ public class LocalSession implements TextureHolder {
} }
this.clipboard = clipboard; this.clipboard = clipboard;
} }
}
/** /**
* @return true always - see deprecation notice * @return true always - see deprecation notice