Exemplo n.º 1
0
        private void EnsureCapacity()
        {
            if (myItems == null)
            {
                myItems = new ValueLifetimed <T> [1];
            }

            if (mySize < myItems.Length)
            {
                return;
            }

            // we have to make new array ALWAYS at this point, because this method could be called during enumeration and we want enumeration to work in a snapshot fashion
            var countAfterCleaning = 0;
            var markerDecrement    = 0;
            var newItems           = new ValueLifetimed <T> [mySize * 2]; //Count can't be zero here

            for (var i = 0; i < mySize; i++)
            {
                if (myItems[i].Lifetime.IsAlive)
                {
                    newItems[countAfterCleaning++] = myItems[i];
                }
                else if (i < Marker)
                {
                    markerDecrement++;
                }
            }

            mySize  = countAfterCleaning;
            Marker -= markerDecrement;
            myItems = newItems;
        }
Exemplo n.º 2
0
 public void AddPriorityItem(ValueLifetimed <T> item)
 {
     EnsureCapacity();
     Array.Copy(myItems, Marker, myItems, Marker + 1, mySize - Marker);
     myItems[Marker++] = item;
     mySize++;
 }
Exemplo n.º 3
0
            public bool MoveNext()
            {
                while (++myPos < mySize)
                {
                    ref var item = ref myItems[myPos];
                    if (item.Lifetime.IsNotAlive)
                    {
                        continue;
                    }

                    myCurValue = item;

                    // double-check `IsAlive` because myCurValue may be partially cleared if ClearValuesIfNotAlive was called at the same time
                    Memory.Barrier(); // to suppress reordering
                    if (item.Lifetime.IsAlive)
                    {
                        return(true);
                    }
                }
Exemplo n.º 4
0
 public void Add(ValueLifetimed <T> item)
 {
     EnsureCapacity();
     myItems[mySize++] = item;
 }