Exemplo n.º 1
0
 private void GetNextEmptyBuffer(out SuperSonicFixedBuffer <T> buffer)
 {
     if (!_emptyBuffersQueue.TryDequeue(out buffer))
     {
         buffer = new SuperSonicFixedBuffer <T>();
     }
 }
Exemplo n.º 2
0
        private void SwitchHeadBuffer(ref SuperSonicFixedBuffer <T> headBuffer)
        {
            var currentBuffer = Volatile.Read(ref headBuffer);

            GetNextEmptyBuffer(out headBuffer);
            if (Interlocked.CompareExchange(ref _headBuffer, headBuffer, currentBuffer) != currentBuffer)
            {
                _emptyBuffersQueue.Enqueue(headBuffer);
                headBuffer = Volatile.Read(ref _headBuffer);
            }
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            _headBuffer = null;

            SuperSonicFixedBuffer <T> item;

            while (_fullBuffersQueue.TryDequeue(out item))
            {
            }
            while (_emptyBuffersQueue.TryDequeue(out item))
            {
            }
        }