internal InternalPartitionEnumerator(IEnumerator <TSource> sharedReader, Partitioner.SharedLong sharedIndex, Partitioner.SharedBool hasNoElementsLeft, object sharedLock, Partitioner.SharedInt activePartitionCount, Partitioner.DynamicPartitionerForIEnumerable <TSource> .InternalPartitionEnumerable enumerable, bool useSingleChunking) : base(sharedReader, sharedIndex, useSingleChunking) { this.m_hasNoElementsLeft = hasNoElementsLeft; this.m_sharedLock = sharedLock; this.m_enumerable = enumerable; this.m_activePartitionCount = activePartitionCount; if (this.m_activePartitionCount == null) { return; } Interlocked.Increment(ref this.m_activePartitionCount.Value); }
internal InternalPartitionEnumerable(IEnumerator <TSource> sharedReader, bool useSingleChunking, bool isStaticPartitioning) { this.m_sharedReader = sharedReader; this.m_sharedIndex = new Partitioner.SharedLong(-1L); this.m_hasNoElementsLeft = new Partitioner.SharedBool(false); this.m_sourceDepleted = new Partitioner.SharedBool(false); this.m_sharedLock = new object(); this.m_useSingleChunking = useSingleChunking; if (!this.m_useSingleChunking) { this.m_FillBuffer = new KeyValuePair <long, TSource> [(PlatformHelper.ProcessorCount > 4 ? 4: 1) * Partitioner.GetDefaultChunkSize <TSource>()]; } if (isStaticPartitioning) { this.m_activePartitionCount = new Partitioner.SharedInt(0); } else { this.m_activePartitionCount = (Partitioner.SharedInt)null; } }
public bool MoveNext() { if (this.m_localOffset == null) { this.m_localOffset = new Partitioner.SharedInt(-1); this.m_currentChunkSize = new Partitioner.SharedInt(0); this.m_doublingCountdown = 3; } if (this.m_localOffset.Value < this.m_currentChunkSize.Value - 1) { ++this.m_localOffset.Value; return(true); } int requestedChunkSize; if (this.m_currentChunkSize.Value == 0) { requestedChunkSize = 1; } else if (this.m_doublingCountdown > 0) { requestedChunkSize = this.m_currentChunkSize.Value; } else { requestedChunkSize = Math.Min(this.m_currentChunkSize.Value * 2, this.m_maxChunkSize); this.m_doublingCountdown = 3; } this.m_doublingCountdown = this.m_doublingCountdown - 1; if (!this.GrabNextChunk(requestedChunkSize)) { return(false); } this.m_localOffset.Value = 0; return(true); }