Exemple #1
0
        public void Enqueue(T value)
        {
            if (this.writeStatus.ElementList.ValueList[this.writeStatus.WriteArrayIndex].Valid)
            {
                int num = this.writeStatus.ElementList.ValueList.Length << 1;
                if (num == -2147483648)
                {
                    throw new OutOfMemoryException("Can't reserve more entry.");
                }
                SingleFreeQueue2 <T> .WriteStatus writeStatus = new SingleFreeQueue2 <T> .WriteStatus();

                writeStatus.ElementList = new SingleFreeQueue2 <T> .ElementList(num);

                writeStatus.ElementList.ValueList[0].Value = value;
                writeStatus.ElementList.ValueList[0].Valid = true;
                writeStatus.WriteSequence   = 1;
                writeStatus.WriteArrayIndex = 1;
                SingleFreeQueue2 <T> .ElementList elementList = this.writeStatus.ElementList;
                this.writeStatus     = writeStatus;
                elementList.NextList = writeStatus.ElementList;
            }
            else
            {
                this.writeStatus.ElementList.ValueList[this.writeStatus.WriteArrayIndex].Value = value;
                this.writeStatus.ElementList.ValueList[this.writeStatus.WriteArrayIndex].Valid = true;
                this.writeStatus.WriteSequence++;
                this.writeStatus.WriteArrayIndex = (this.writeStatus.WriteSequence & this.writeStatus.ElementList.ValueList.Length - 1);
            }
        }
Exemple #2
0
        public void Clear()
        {
            SingleFreeQueue2 <T> .WriteStatus writeStatus = this.writeStatus;
            if (this.readStatus.ElementList != writeStatus.ElementList)
            {
                this.readStatus.ReadArrayIndex = 0;
                this.readStatus.ReadSequence   = 0;
                while (this.readStatus.ElementList != writeStatus.ElementList)
                {
                    this.readStatus.ElementList = this.readStatus.ElementList.NextList;
                }
            }
            int num           = this.readStatus.ElementList.ValueList.Length;
            int writeSequence = writeStatus.WriteSequence;
            int num2          = writeSequence & num - 1;

            if (this.readStatus.ReadArrayIndex < num2)
            {
                Array.Clear(this.readStatus.ElementList.ValueList, this.readStatus.ReadArrayIndex, writeSequence - this.readStatus.ReadSequence);
            }
            else if (writeSequence - this.readStatus.ReadSequence > 0)
            {
                Array.Clear(this.readStatus.ElementList.ValueList, this.readStatus.ReadArrayIndex, num - this.readStatus.ReadArrayIndex);
                Array.Clear(this.readStatus.ElementList.ValueList, 0, num2);
            }
            this.readStatus.ReadSequence   = writeSequence;
            this.readStatus.ReadArrayIndex = num2;
            Array.Clear(this.readStatus.CachedValueList, 0, this.readStatus.CachedValueList.Length);
            this.readStatus.Index = 0;
        }
Exemple #3
0
        private void ExtendThreadQueue(int threadID)
        {
            int i;

            for (i = this.threadLocalQueue.Length * 2; i <= threadID; i *= 2)
            {
            }
            SingleFreeQueue2 <KeyValuePair <int, T> >[] destinationArray = new SingleFreeQueue2 <KeyValuePair <int, T> > [i];
            Array.Copy(this.threadLocalQueue, destinationArray, this.threadLocalQueue.Length);
            this.threadLocalQueue = destinationArray;
        }
Exemple #4
0
        private void LoadCache()
        {
            bool flag = this.readStatus.ElementList.NextList != null;

            if (!this.readStatus.ElementList.ValueList[this.readStatus.ReadArrayIndex].Valid)
            {
                if (!flag)
                {
                    return;
                }
                this.readStatus.ReadSequence   = 0;
                this.readStatus.ReadArrayIndex = 0;
                this.readStatus.ElementList    = this.readStatus.ElementList.NextList;
            }
            int num = this.readStatus.ElementList.ValueList.Length;

            SingleFreeQueue2 <T> .WriteStatus writeStatus = this.writeStatus;
            int num2;

            if (writeStatus.ElementList == this.readStatus.ElementList)
            {
                num2 = writeStatus.WriteSequence - this.readStatus.ReadSequence;
                if (num2 > this.cacheLength)
                {
                    num2 = this.cacheLength;
                }
            }
            else
            {
                num2 = this.cacheLength;
            }
            if (this.readStatus.ReadArrayIndex + num2 > num)
            {
                num2 = num - this.readStatus.ReadArrayIndex;
            }
            Array.Copy(this.readStatus.ElementList.ValueList, this.readStatus.ReadArrayIndex, this.readStatus.CachedValueList, 0, num2);
            Array.Clear(this.readStatus.ElementList.ValueList, this.readStatus.ReadArrayIndex, num2);
            this.readStatus.ReadSequence  += num2;
            this.readStatus.ReadArrayIndex = (this.readStatus.ReadSequence & num - 1);
        }
Exemple #5
0
        public void Enqueue(IEnumerable <T> collection)
        {
            SingleFreeQueue2 <T> .ElementList elementList  = null;
            SingleFreeQueue2 <T> .ElementList elementList2 = this.writeStatus.ElementList;
            int num  = this.writeStatus.WriteSequence;
            int num2 = this.writeStatus.WriteArrayIndex;
            int num3 = 0;

            try
            {
                foreach (T value in collection)
                {
                    if (elementList2.ValueList[num2].Valid)
                    {
                        int num4 = elementList2.ValueList.Length << 1;
                        if (num4 == -2147483648)
                        {
                            throw new OutOfMemoryException("Can't reserve more entry.");
                        }
                        SingleFreeQueue2 <T> .ElementList elementList3 = new SingleFreeQueue2 <T> .ElementList(num4);

                        if (elementList == null)
                        {
                            elementList  = elementList3;
                            elementList2 = elementList3;
                            num3         = num - this.writeStatus.WriteSequence;
                        }
                        else
                        {
                            elementList2.NextList = elementList3;
                            elementList2          = elementList3;
                        }
                        num  = 0;
                        num2 = 0;
                    }
                    elementList2.ValueList[num2].Value = value;
                    elementList2.ValueList[num2].Valid = true;
                    num++;
                    num2 = (num & elementList2.ValueList.Length - 1);
                }
                if (elementList == null)
                {
                    this.writeStatus.WriteSequence   = num;
                    this.writeStatus.WriteArrayIndex = num2;
                }
                else
                {
                    SingleFreeQueue2 <T> .WriteStatus writeStatus = new SingleFreeQueue2 <T> .WriteStatus();

                    writeStatus.ElementList     = elementList2;
                    writeStatus.WriteSequence   = num;
                    writeStatus.WriteArrayIndex = num2;
                    SingleFreeQueue2 <T> .ElementList elementList4 = this.writeStatus.ElementList;
                    this.writeStatus      = writeStatus;
                    elementList4.NextList = elementList;
                }
            }
            catch (OutOfMemoryException)
            {
                if (elementList == null)
                {
                    num3 = num - this.writeStatus.WriteSequence;
                }
                if (this.writeStatus.WriteArrayIndex + num3 > this.writeStatus.ElementList.ValueList.Length)
                {
                    int num5 = this.writeStatus.ElementList.ValueList.Length - this.writeStatus.WriteArrayIndex;
                    Array.Clear(this.writeStatus.ElementList.ValueList, this.writeStatus.WriteArrayIndex, num5);
                    Array.Clear(this.writeStatus.ElementList.ValueList, 0, num3 - num5);
                }
                else
                {
                    Array.Clear(this.writeStatus.ElementList.ValueList, this.writeStatus.WriteArrayIndex, num3);
                }
                throw;
            }
        }
Exemple #6
0
        public void Enqueue <U>(ArraySegment <U> collection, Converter <U, T> converter)
        {
            SingleFreeQueue2 <T> .ElementList elementList  = null;
            SingleFreeQueue2 <T> .ElementList elementList2 = this.writeStatus.ElementList;
            int num  = this.writeStatus.WriteSequence;
            int num2 = this.writeStatus.WriteArrayIndex;
            int num3 = 0;

            try
            {
                for (int i = 0; i < collection.Count; i++)
                {
                    if (elementList2.ValueList[num2].Valid)
                    {
                        int num4 = elementList2.ValueList.Length << 1;
                        if (num4 == -2147483648)
                        {
                            throw new OutOfMemoryException("Can't reserve more entry.");
                        }
                        SingleFreeQueue2 <T> .ElementList elementList3 = new SingleFreeQueue2 <T> .ElementList(num4);

                        if (elementList == null)
                        {
                            elementList  = elementList3;
                            elementList2 = elementList3;
                            num3         = num - this.writeStatus.WriteSequence;
                        }
                        else
                        {
                            elementList2.NextList = elementList3;
                            elementList2          = elementList3;
                        }
                        num  = 0;
                        num2 = 0;
                    }
                    elementList2.ValueList[num2].Value = converter(collection.Array[i + collection.Offset]);
                    elementList2.ValueList[num2].Valid = true;
                    num++;
                    num2 = (num & elementList2.ValueList.Length - 1);
                }
                if (elementList == null)
                {
                    this.writeStatus.WriteSequence   = num;
                    this.writeStatus.WriteArrayIndex = num2;
                }
                else
                {
                    SingleFreeQueue2 <T> .WriteStatus writeStatus = new SingleFreeQueue2 <T> .WriteStatus();

                    writeStatus.ElementList     = elementList2;
                    writeStatus.WriteSequence   = num;
                    writeStatus.WriteArrayIndex = num2;
                    SingleFreeQueue2 <T> .ElementList elementList4 = this.writeStatus.ElementList;
                    this.writeStatus      = writeStatus;
                    elementList4.NextList = elementList;
                }
            }
            catch (OutOfMemoryException)
            {
                if (elementList == null)
                {
                    num3 = num - this.writeStatus.WriteSequence;
                }
                if (this.writeStatus.WriteArrayIndex + num3 > this.writeStatus.ElementList.ValueList.Length)
                {
                    int num5 = this.writeStatus.ElementList.ValueList.Length - this.writeStatus.WriteArrayIndex;
                    Array.Clear(this.writeStatus.ElementList.ValueList, this.writeStatus.WriteArrayIndex, num5);
                    Array.Clear(this.writeStatus.ElementList.ValueList, 0, num3 - num5);
                }
                else
                {
                    Array.Clear(this.writeStatus.ElementList.ValueList, this.writeStatus.WriteArrayIndex, num3);
                }
                throw;
            }
        }