Exemple #1
0
        protected sealed override long ReserveEarliestAvailable(int requiredPermits, long nowMicros)
        {
            Resync(nowMicros);
            var returnValue          = _nextFreeTicketMicros;
            var storedPermitsToSpend = Math.Min(requiredPermits, _storedPermits);
            var freshPermits         = requiredPermits - storedPermitsToSpend;
            var waitMicros           = StoredPermitsToWaitTime(_storedPermits, storedPermitsToSpend)
                                       + (long)(freshPermits * _stableIntervalMicros);

            _nextFreeTicketMicros = LongMath.SaturatedAdd(_nextFreeTicketMicros, waitMicros);
            _storedPermits       -= storedPermitsToSpend;
            return(returnValue);
        }