Amib.Threading.Internal.WorkItemsQueue.RemoveWaiter C# (CSharp) Method

RemoveWaiter() private method

Remove a waiter from the stack
private RemoveWaiter ( WaiterEntry waiterEntry, bool popDecrement ) : void
waiterEntry WaiterEntry A waiter entry to remove
popDecrement bool If true the waiter count is always decremented
return void
        private void RemoveWaiter(WaiterEntry waiterEntry, bool popDecrement)
        {
            // Store the prev entry in the list
            WaiterEntry prevWaiterEntry = waiterEntry._prevWaiterEntry;

            // Store the next entry in the list
            WaiterEntry nextWaiterEntry = waiterEntry._nextWaiterEntry;

            // A flag to indicate if we need to decrement the waiters count.
            // If we got here from PopWaiter then we must decrement.
            // If we got here from PushWaiter then we decrement only if
            // the waiter was already in the stack.
            bool decrementCounter = popDecrement;

            // Null the waiter's entry links
            waiterEntry._prevWaiterEntry = null;
            waiterEntry._nextWaiterEntry = null;

            // If the waiter entry had a prev link then update it.
            // It also means that the waiter is already in the list and we
            // need to decrement the waiters count.
            if (null != prevWaiterEntry)
            {
                prevWaiterEntry._nextWaiterEntry = nextWaiterEntry;
                decrementCounter = true;
            }

            // If the waiter entry had a next link then update it.
            // It also means that the waiter is already in the list and we
            // need to decrement the waiters count.
            if (null != nextWaiterEntry)
            {
                nextWaiterEntry._prevWaiterEntry = prevWaiterEntry;
                decrementCounter = true;
            }

            // Decrement the waiters count if needed
            if (decrementCounter)
            {
                --_waitersCount;
            }
        }