class Timestamper {

    public static long next() {
        int runs = 0;
        while (true) {
            long base = SlewClock.timeMillis() << BIN_DIGITS;
            long maxValue = base + ONE_MS - 1;

            for (long current = VALUE.get(), update = Math.max(base, current + 1); update < maxValue;
                 current = VALUE.get(), update = Math.max(base, current + 1)) {
                if (VALUE.compareAndSet(current, update)) {
                    if (runs > 1) {
                        log(base, "Thread spin-waits on time to pass. Looped "
                                  + "{} times, you might want to increase -Dnet.sf.ehcache.util.Timestamper.shift", runs);
                    }
                    return update;
                }
            }
            ++runs;
        }
    }

    private  Timestamper();

}