mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-16 13:21:32 +01:00
Fix potential race condition in MRUCache
This commit is contained in:
parent
6cb0f5e810
commit
21ae1dbac0
@ -46,13 +46,21 @@ public abstract class MRUCache<T> {
|
||||
}
|
||||
|
||||
protected void offerRecent(int validAt, T offer) {
|
||||
synchronized (this) {
|
||||
if (validAt == this.modCount.get()) {
|
||||
this.recent = offer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling clearRecent effectively resets the instance. any other threads going to call
|
||||
* offerRecent in the future with the previous mod count will be ignored.
|
||||
*/
|
||||
protected void clearRecent() {
|
||||
synchronized (this) {
|
||||
this.recent = null;
|
||||
this.modCount.incrementAndGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user