private void CheckWaitingReads() { if (!readLocked.HasValue && waitingReads.Count > 0) { WaitingRead wr = waitingReads.Peek(); if (items.Count >= wr.desiredItems || (eofSignaled && !writeLocked.HasValue && waitingWrites.Count == 0)) { waitingReads.Dequeue(); readLocked = Math.Min(wr.desiredItems, items.Count); wr.k.PostResult(new AcquireReadSucceeded <T>(readPtr, readLocked.Value == 0 ? ImmutableList <T> .Empty : items.GetRange(0, readLocked.Value))); if (wr.ctr.HasValue) { wr.ctr.Value.PostDispose(); } if (readLocked.Value == 0) { while (waitingReads.Count > 0) { WaitingRead wr2 = waitingReads.Dequeue(); wr2.k.PostResult(new AcquireReadSucceeded <T>(readPtr, ImmutableList <T> .Empty)); if (wr2.ctr.HasValue) { wr2.ctr.Value.PostDispose(); } } } } } }
private void CheckWaitingWrites() { if (!writeLocked.HasValue && waitingWrites.Count > 0) { WaitingWrite ww = waitingWrites.Peek(); System.Diagnostics.Debug.Assert(capacity.HasValue, "If there is no capacity limit, there should never be any waiting writes"); // ReSharper disable once PossibleInvalidOperationException if (capacity.Value - items.Count >= ww.desiredSpace) { waitingWrites.Dequeue(); writeLocked = ww.desiredSpace; ww.k.PostResult(new AcquireWriteSucceeded(readPtr + items.Count, ww.desiredSpace)); if (ww.ctr.HasValue) { ww.ctr.Value.PostDispose(); } } } }