public BlockingProducerConsumerQueue( int?maxSize = null, BlockingImplementationType blockingImplementationType = BlockingImplementationType.Mutex) //By default, if maxSize > 0 then OverflowBehavior.Blocking behavior is providing, however, in case of bounded queue OverflowBehavior.NonBlocking behavior can exist : this(maxSize, blockingImplementationType, maxSize > 0 ? BufferType.Bounded : BufferType.Unbounded, maxSize > 0 ? OverflowBehavior.Blocking : OverflowBehavior.NonBlocking) { if (maxSize == 0) { throw new ArgumentOutOfRangeException("BlockingProducerConsumerQueue cannot have empty size"); } _maxSize = maxSize; }
private BlockingProducerConsumerQueue( int?maxSize, BlockingImplementationType blockingImplementationType, BufferType bufferType, OverflowBehavior overflowBehavior) { _blockingImplementationType = blockingImplementationType; _bufferType = bufferType; switch (_blockingImplementationType) { case BlockingImplementationType.Mutex: { _safeWaitAndAcquireHandle = new MutexWaitAndAcquireHandle(); break; } case BlockingImplementationType.Monitor: { _safeWaitAndAcquireHandle = new MonitorWaitAndAcquireHandle(); break; } default: throw new NotSupportedException($"{blockingImplementationType} is not supported"); } _overflowBehavior = overflowBehavior; if (bufferType == BufferType.Bounded) { _itemsContainer = new BoundedFifo <T>(maxSize.Value); } else { _itemsContainer = new UnboundedFifo <T>(); } }