mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 04:29:05 +00:00
Fixes
This commit is contained in:
@@ -9,11 +9,16 @@ public class AtomicCache<T>
|
||||
{
|
||||
private transient volatile T t;
|
||||
private transient volatile long a;
|
||||
private boolean nullSupport;
|
||||
private transient volatile int validations;
|
||||
private final IrisLock check;
|
||||
private final IrisLock time;
|
||||
private final IrisLock write;
|
||||
private final boolean nullSupport;
|
||||
|
||||
public AtomicCache()
|
||||
{
|
||||
this(false);
|
||||
}
|
||||
|
||||
public AtomicCache(boolean nullSupport)
|
||||
{
|
||||
@@ -26,11 +31,6 @@ public class AtomicCache<T>
|
||||
t = null;
|
||||
}
|
||||
|
||||
public AtomicCache()
|
||||
{
|
||||
this(false);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
check.lock();
|
||||
@@ -43,7 +43,51 @@ public class AtomicCache<T>
|
||||
check.unlock();
|
||||
}
|
||||
|
||||
public T aquireNullex(Supplier<T> t)
|
||||
public T aquire(Supplier<T> t)
|
||||
{
|
||||
if(nullSupport)
|
||||
{
|
||||
return aquireNull(t);
|
||||
}
|
||||
|
||||
if(this.t != null && validations > 1000)
|
||||
{
|
||||
return this.t;
|
||||
}
|
||||
|
||||
if(this.t != null && M.ms() - a > 1000)
|
||||
{
|
||||
if(this.t != null)
|
||||
{
|
||||
validations++;
|
||||
}
|
||||
|
||||
return this.t;
|
||||
}
|
||||
|
||||
check.lock();
|
||||
|
||||
if(this.t == null)
|
||||
{
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if(a == -1)
|
||||
{
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
}
|
||||
|
||||
check.unlock();
|
||||
return this.t;
|
||||
}
|
||||
|
||||
public T aquireNull(Supplier<T> t)
|
||||
{
|
||||
if(validations > 1000)
|
||||
{
|
||||
@@ -72,48 +116,4 @@ public class AtomicCache<T>
|
||||
check.unlock();
|
||||
return this.t;
|
||||
}
|
||||
|
||||
public T aquire(Supplier<T> t)
|
||||
{
|
||||
if(nullSupport)
|
||||
{
|
||||
return aquireNullex(t);
|
||||
}
|
||||
|
||||
if(this.t != null && validations > 1000)
|
||||
{
|
||||
return this.t;
|
||||
}
|
||||
|
||||
if(this.t != null && M.ms() - a > 1000)
|
||||
{
|
||||
if(this.t != null)
|
||||
{
|
||||
validations++;
|
||||
}
|
||||
|
||||
return this.t;
|
||||
}
|
||||
|
||||
check.lock();
|
||||
|
||||
if(this.t != null)
|
||||
{
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if(a == -1)
|
||||
{
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
}
|
||||
|
||||
check.unlock();
|
||||
return this.t;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user