Akka.Interfaced.SlimSocket.Server.InterlockedCountFlag.DecrementWithSetFlag C# (CSharp) Метод

DecrementWithSetFlag() публичный Метод

public DecrementWithSetFlag ( ) : bool
Результат bool
        public bool DecrementWithSetFlag()
        {
            while (true)
            {
                var v = _value;
                if (v < 2)
                    throw new InvalidOperationException("Already Zero");
                var vNew = ((v - 2) & 0x7FFFFFFE) + 1;
                if (Interlocked.CompareExchange(ref _value, vNew, v) == v)
                    return vNew == 1;
            }
        }
    }

Usage Example

        private void HandleSocketError(SocketError error)
        {
            if (_logger != null)
            {
                _logger.TraceFormat("HandleSocketError: {0}", error);
            }

            if (_closeReason == 0)
            {
                _closeReason = (int)error;
            }

            _socket.Close();
            if (_issueCountFlag.DecrementWithSetFlag())
            {
                ProcessClose();
            }
        }