System.Net.InterlockedGate.Complete C# (CSharp) Method

Complete() private method

private Complete ( ) : bool
return bool
        internal bool Complete()
        {
            int gate;

            // Spin while the gate is being held, allowing the other thread to set invariants up.
            while ((gate = Interlocked.CompareExchange(ref m_State, Closed, Triggered)) != Triggered)
            {
                if (gate == Closed)
                {
                    return false;
                }

                if (gate == Open)
                {
                    if (Interlocked.CompareExchange(ref m_State, Closed, Open) == Open)
                    {
                        return false;
                    }

                    continue;
                }

                // gate == Held
                Thread.SpinWait(1);
            }

            return true;
        }
    }