AsyncDolls.AsyncCountdownEvent.ModifyCount C# (CSharp) Method

ModifyCount() private method

Attempts to modify the current count by the specified amount. This method returns false if the new current count value would be invalid, or if the count has already reached zero.
private ModifyCount ( int signalCount ) : bool
signalCount int The amount to change the current count. This may be positive or negative, but not zero.
return bool
        private bool ModifyCount(int signalCount)
        {
            while (true)
            {
                int oldCount = CurrentCount;
                if (oldCount == 0)
                    return false;
                int newCount = oldCount + signalCount;
                if (newCount < 0)
                    return false;
                if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount)
                {
                    //Enlightenment.Trace.AsyncCountdownEvent_CountChanged(this, oldCount, newCount);
                    if (newCount == 0)
                        _tcs.SetResult();
                    return true;
                }
            }
        }