public virtual void Reset() { this.writedLength = 0; this.readedLength = 0; base.RunningIndex = 0; this.ChildSegment = null; }
public void WriterAdvance() { if (awaitWriteSegment == null) { throw new NullReferenceException(nameof(awaitWriteSegment)); } lock (this.sync) { var segment = this.awaitWriteSegment; this.awaitWriteSegment = null; if (this.headBufferSegment == null && this.tailBufferSegment == null) { this.headBufferSegment = segment; this.tailBufferSegment = segment; } else { this.tailBufferSegment.SetNext(segment); this.tailBufferSegment = segment; } } }
public virtual void Dispose() { this.length = 0; this.writedLength = 0; this.readedLength = 0; this.availableMemory = default; base.Memory = default; base.RunningIndex = 0; this.ChildSegment = null; }
public void SetNext(ASegment segment) { this.ChildSegment = segment; segment = this; while (segment.Next != null) { segment.ChildSegment.RunningIndex = segment.RunningIndex + segment.writedLength; segment = segment.ChildSegment; } }
public void Complete() { if (this.isDispose) { return; } this.isDispose = true; lock (this.sync) { if (this.awaitWriteSegment != null) { this.awaitWriteSegment.Dispose(); #if DEBUG Interlocked.Increment(ref d_count); #endif } ASegment segment = this.headBufferSegment; while (segment != null) { ASegment returnSegment = segment; segment = segment.ChildSegment; returnSegment.Dispose(); #if DEBUG Interlocked.Increment(ref d_count); #endif } } this.memoryPool = null; while (this.segmentStack.TryPop(out var item)) { item.Dispose(); #if DEBUG Interlocked.Increment(ref d_count); #endif } this.segmentStack.Clear(); #if DEBUG Logger.Info($"create buffer count:{this.c_count}, recycle buffer count:{this.d_count}"); #endif }
public MemorySegment GetSegment() { if (this.awaitWriteSegment != null) { return(this.awaitWriteSegment as MemorySegment); } MemorySegment segment; if (!this.segmentStack.TryPop(out segment)) { segment = new MemorySegment(this.segmentStack); segment.SetMemoryBlock(this.memoryPool.Rent()); #if DEBUG Interlocked.Increment(ref c_count); #endif } this.awaitWriteSegment = segment; return(segment); }
public void ReaderAdvance(int count) { lock (this.sync) { while (count > 0) { if (this.headBufferSegment == null) { throw new ArgumentOutOfRangeException("The Segment is not enough"); } var segment = this.headBufferSegment.ChildSegment; this.headBufferSegment.Reset(); this.headBufferSegment = segment; count--; if (this.headBufferSegment == null) { this.headBufferSegment = null; this.tailBufferSegment = null; } } } }
internal static long GetLength(long startPosition, ASegment endSegment, int endIndex) { return((endSegment.RunningIndex + (uint)endIndex) - startPosition); }
internal static long GetLength(ASegment startSegment, int startIndex, ASegment endSegment, int endIndex) { return((endSegment.RunningIndex + (uint)endIndex) - (startSegment.RunningIndex + (uint)startIndex)); }