in harry-core/src/harry/model/clock/ApproximateMonotonicClock.java [124:152]
private void rebase()
{
int arrayIdx = idx % historySize;
long rebaseLts = lts.get();
if (rebaseLts == DEFUNCT)
throw new IllegalStateException();
while (!lts.compareAndSet(rebaseLts, REBASE_IN_PROGRESS))
rebaseLts = lts.get();
ltsHistory.set(arrayIdx, rebaseLts == START_VALUE ? START_VALUE : (rebaseLts + 1));
// If we happen to exhaust counter, we just need to make operations "wider".
// It is unsafe to proceed, so we defunct the clock.
//
// We could make a clock implementation that would sleep on `get`, but it will
// be more expensive, since we'll have to check for overflow each time before
// returning anything.
if (idx > 1 && get(idx) - get(idx - 1) > periodMicros)
{
lts.set(DEFUNCT);
executor.shutdown();
throwCounterExhaustedException();
}
idx = idx + 1;
if (!lts.compareAndSet(REBASE_IN_PROGRESS, rebaseLts))
throw new IllegalStateException("No thread should have changed LTS during rebase. " + lts.get());
}