mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-26 01:51:26 +01:00
CAS to reset acquiring time
This commit is contained in:
parent
c5d1d8bc36
commit
ad3e723437
@ -312,11 +312,10 @@ final class ServerProcessImpl implements ServerProcess {
|
|||||||
|
|
||||||
// Monitoring
|
// Monitoring
|
||||||
{
|
{
|
||||||
final double acquisitionTimeMs = Acquirable.getAcquiringTime() / 1e6D;
|
final double acquisitionTimeMs = Acquirable.resetAcquiringTime() / 1e6D;
|
||||||
final double tickTimeMs = (System.nanoTime() - nanoTime) / 1e6D;
|
final double tickTimeMs = (System.nanoTime() - nanoTime) / 1e6D;
|
||||||
final TickMonitor tickMonitor = new TickMonitor(tickTimeMs, acquisitionTimeMs);
|
final TickMonitor tickMonitor = new TickMonitor(tickTimeMs, acquisitionTimeMs);
|
||||||
EventDispatcher.call(new ServerTickMonitorEvent(tickMonitor));
|
EventDispatcher.call(new ServerTickMonitorEvent(tickMonitor));
|
||||||
Acquirable.resetAcquiringTime();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,22 +33,16 @@ public sealed interface Acquirable<T> permits AcquirableImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the time spent acquiring since last tick.
|
* Retrieve and reset acquiring time.
|
||||||
*
|
|
||||||
* @return the acquiring time
|
|
||||||
*/
|
|
||||||
static long getAcquiringTime() {
|
|
||||||
return AcquirableImpl.WAIT_COUNTER_NANO.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets {@link #getAcquiringTime()}.
|
|
||||||
* <p>
|
|
||||||
* Mostly for internal use.
|
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
static void resetAcquiringTime() {
|
static long resetAcquiringTime() {
|
||||||
AcquirableImpl.WAIT_COUNTER_NANO.set(0);
|
do {
|
||||||
|
final long acquiringTime = AcquirableImpl.WAIT_COUNTER_NANO.get();
|
||||||
|
if (AcquirableImpl.WAIT_COUNTER_NANO.compareAndSet(acquiringTime, 0)) {
|
||||||
|
return acquiringTime;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user