System.Threading.Interlocked.CompareExchange C# (CSharp) Méthode

CompareExchange() private méthode

private CompareExchange ( int &location1, int value, int comparand ) : int
location1 int
value int
comparand int
Résultat int
        public static extern int CompareExchange(ref int location1, int value, int comparand);
    }

Usage Example

Exemple #1
0
        public override void Add(T element)
        {
            int index         = Interlocked.Increment(ref _index) - 1;
            int adjustedIndex = index;

            int arrayIndex = GetArrayIndex(index + 1);

            if (arrayIndex > 0)
            {
                adjustedIndex -= Counts[arrayIndex - 1];
            }

            if (_array[arrayIndex] == null)
            {
                int arrayLength = Sizes[arrayIndex];
                Interlocked.CompareExchange(ref _array[arrayIndex], new T[arrayLength], null);
            }

            _array[arrayIndex][adjustedIndex] = element;

            int count      = _count;
            int fuzzyCount = Interlocked.Increment(ref _fuzzyCount);

            if (fuzzyCount == index + 1)
            {
                Interlocked.CompareExchange(ref _count, fuzzyCount, count);
            }
            ItemAddedEvent?.Invoke(element, index);
        }
All Usage Examples Of System.Threading.Interlocked::CompareExchange