mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 07:31:47 +01:00
Synchronize cache access
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
85559abb28
commit
ac4d78acf1
@ -111,20 +111,20 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
}
|
}
|
||||||
entries[index] = new Entry<>(tag, nbt);
|
entries[index] = new Entry<>(tag, nbt);
|
||||||
}
|
}
|
||||||
|
synchronized (this) {
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NBTCompound asCompound() {
|
public @NotNull NBTCompound asCompound() {
|
||||||
return updatedCache().compound;
|
return updatedCache().compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache updatedCache() {
|
private synchronized Cache updatedCache() {
|
||||||
Cache cache = this.cache;
|
Cache cache = this.cache;
|
||||||
if (cache == null) {
|
if (cache == null) {
|
||||||
synchronized (this) {
|
|
||||||
if ((cache = this.cache) != null) return cache;
|
|
||||||
Entry<?>[] entries = this.entries;
|
Entry<?>[] entries = this.entries;
|
||||||
if (entries.length > 0) {
|
if (entries.length > 0) {
|
||||||
entries = entries.clone();
|
entries = entries.clone();
|
||||||
@ -146,7 +146,6 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
}
|
}
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user