mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-11 19:00:52 +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
|
||||
{
|
||||
final double acquisitionTimeMs = Acquirable.getAcquiringTime() / 1e6D;
|
||||
final double acquisitionTimeMs = Acquirable.resetAcquiringTime() / 1e6D;
|
||||
final double tickTimeMs = (System.nanoTime() - nanoTime) / 1e6D;
|
||||
final TickMonitor tickMonitor = new TickMonitor(tickTimeMs, acquisitionTimeMs);
|
||||
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.
|
||||
*
|
||||
* @return the acquiring time
|
||||
*/
|
||||
static long getAcquiringTime() {
|
||||
return AcquirableImpl.WAIT_COUNTER_NANO.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets {@link #getAcquiringTime()}.
|
||||
* <p>
|
||||
* Mostly for internal use.
|
||||
* Retrieve and reset acquiring time.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
static void resetAcquiringTime() {
|
||||
AcquirableImpl.WAIT_COUNTER_NANO.set(0);
|
||||
static long resetAcquiringTime() {
|
||||
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