示例#1
0
        internal bool CommitUnsynchronized()
        {
            _operationState.EndWrite();

            if (_currentWriteLength == 0)
            {
                // Nothing written to commit
                return(true);
            }

            // Always move the read tail to the write head
            _readTail      = _writingHead;
            _readTailIndex = _writingHead.End;

            long oldLength = _length;

            _length += _currentWriteLength;

            // Do not reset if reader is complete
            if (_pauseWriterThreshold > 0 &&
                oldLength < _pauseWriterThreshold &&
                _length >= _pauseWriterThreshold &&
                !_readerCompletion.IsCompleted)
            {
                _writerAwaitable.SetUncompleted();
            }

            _currentWriteLength = 0;

            return(false);
        }
示例#2
0
文件: Pipe.cs 项目: yang123vc/corefx
        internal bool CommitUnsynchronized()
        {
            _operationState.EndWrite();

            if (_unflushedBytes == 0)
            {
                // Nothing written to commit
                return(true);
            }

            // Update the writing head
            _writingHead.End += _writingHeadBytesBuffered;

            // Always move the read tail to the write head
            _readTail      = _writingHead;
            _readTailIndex = _writingHead.End;

            long oldLength = _unconsumedBytes;

            _unconsumedBytes += _unflushedBytes;

            // Do not reset if reader is complete
            if (_pauseWriterThreshold > 0 &&
                oldLength < _pauseWriterThreshold &&
                _unconsumedBytes >= _pauseWriterThreshold &&
                !_readerCompletion.IsCompleted)
            {
                _writerAwaitable.SetUncompleted();
            }

            _unflushedBytes           = 0;
            _writingHeadBytesBuffered = 0;

            return(false);
        }
示例#3
0
        internal bool CommitUnsynchronized()
        {
            _operationState.EndWrite();

            if (_unflushedBytes == 0)
            {
                // Nothing written to commit
                return(false);
            }

            // Update the writing head
            Debug.Assert(_writingHead != null);
            _writingHead.End += _writingHeadBytesBuffered;

            // Always move the read tail to the write head
            _readTail      = _writingHead;
            _readTailIndex = _writingHead.End;

            long oldLength = _unconsumedBytes;

            _unconsumedBytes += _unflushedBytes;

            bool resumeReader = true;

            if (_unconsumedBytes < _minimumReadBytes)
            {
                // Don't yield the reader if we haven't written enough
                resumeReader = false;
            }
            // We only apply back pressure if the reader isn't paused. This is important
            // because if it is blocked then this could cause a deadlock (if resumeReader is false).
            // If we are resuming the reader, then we can look at the pause threshold to know
            // if we should pause the writer.
            else if (PauseWriterThreshold > 0 &&
                     oldLength < PauseWriterThreshold &&
                     _unconsumedBytes >= PauseWriterThreshold &&
                     !_readerCompletion.IsCompleted)
            {
                _writerAwaitable.SetUncompleted();
            }

            _unflushedBytes           = 0;
            _writingHeadBytesBuffered = 0;

            return(resumeReader);
        }