public SingleLinks5 <T> AppendNew(int length) { var temp = new SingleLinks5 <T>(length); temp.Next = Next; Next = temp; return(temp); }
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>(); }); }
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; }
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; }