Exemplo n.º 1
0
        public SingleLinks5 <T> AppendNew(int length)
        {
            var temp = new SingleLinks5 <T>(length);

            temp.Next = Next;
            Next      = temp;
            return(temp);
        }
Exemplo n.º 2
0
        public CircleTaskBuffer()
        {
            var first = new SingleLinks5 <T>(ArrayLength);

            first.InReading = true;
            first.Next      = first;
            _writePtr       = first;
            _readPtr        = first;
            _currentWrite   = first.Buffer;
            _currentRead    = first.Buffer;
            Parallel.For(0, ArrayLength, (index) => { _currentWrite[index] = new ManualResetValueTaskSource <T>(); });
        }
Exemplo n.º 3
0
        private void CollectBuffer()
        {
            SpinWait wait = default;

            while (Interlocked.CompareExchange(ref _lock, 1, 0) != 0)
            {
                wait.SpinOnce();
            }
            _readPtr.InReading = false;
            _readPtr           = _readPtr.Next;
            _readPtr.InReading = true;
            _lock        = 0;
            _read_offset = 0;
            _currentRead = _readPtr.Buffer;
        }
Exemplo n.º 4
0
        private void AddBuffer()
        {
            SpinWait wait = default;

            while (Interlocked.CompareExchange(ref _lock, 1, 0) != 0)
            {
                wait.SpinOnce();
            }
            if (_writePtr.Next.InReading)
            {
                _writePtr     = _writePtr.AppendNew(ArrayLength);
                _lock         = 0;
                _currentWrite = _writePtr.Buffer;
                Parallel.For(0, ArrayLength, (index) => { _currentWrite[index] = new ManualResetValueTaskSource <T>(); });
            }
            else
            {
                _writePtr     = _writePtr.Next;
                _currentWrite = _writePtr.Buffer;
                _lock         = 0;
            }
            _write_offset = 0;
        }