예제 #1
0
 private void GetNextEmptyBuffer(out SuperSonicFixedBuffer <T> buffer)
 {
     if (!_emptyBuffersQueue.TryDequeue(out buffer))
     {
         buffer = new SuperSonicFixedBuffer <T>();
     }
 }
예제 #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);
            }
        }
예제 #3
0
        public void Dispose()
        {
            _headBuffer = null;

            SuperSonicFixedBuffer <T> item;

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