private void UpdateConfiguration(int?iops) { long oldState; long newState; if (iops == null || iops < 1) { do { oldState = _stateUpdater.get(this); int disabledCounter = GetDisabledCounter(oldState); disabledCounter |= 1; // Raise the "permanently disabled" bit. newState = ComposeState(disabledCounter, NO_LIMIT); } while (!_stateUpdater.compareAndSet(this, oldState, newState)); } else { do { oldState = _stateUpdater.get(this); int disabledCounter = GetDisabledCounter(oldState); disabledCounter &= unchecked (( int )0xFFFFFFFE); // Mask off "permanently disabled" bit. int iopq = iops / _quantumsPerSecond; newState = ComposeState(disabledCounter, iopq); } while (!_stateUpdater.compareAndSet(this, oldState, newState)); } }
internal virtual bool CheckExpiredAndSetLastCheckTime() { long now = Clock.millis(); long check = this.LastCheck; if (check > now - TimeLimitMillis) { return(true); } while (!LastCheck.compareAndSet(this, check, now)) { check = LastCheck; if (check > now) { break; } } return(false); }