/// <summary>
 /// Creates a new async-compatible producer/consumer collection wrapping the specified collection and with a maximum element count.
 /// </summary>
 /// <param name="collection">The collection to wrap.</param>
 /// <param name="maxCount">The maximum element count. This must be greater than zero.</param>
 public AsyncCollection(IProducerConsumerCollection <T> collection, int maxCount)
 {
     collection = collection ?? new ConcurrentQueue <T>();
     if (maxCount <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(maxCount), "The maximum count must be greater than zero.");
     }
     if (maxCount < collection.Count)
     {
         throw new ArgumentException("The maximum count cannot be less than the number of elements in the collection.", nameof(maxCount));
     }
     _collection          = collection;
     _maxCount            = maxCount;
     _mutex               = new AsyncLock();
     _completedOrNotFull  = new AsyncConditionVariable(_mutex);
     _completedOrNotEmpty = new AsyncConditionVariable(_mutex);
 }
        /// <summary>
        /// Creates a new async-compatible producer/consumer queue with the specified initial elements and a maximum element count.
        /// </summary>
        /// <param name="collection">The initial elements to place in the queue. This may be <c>null</c> to start with an empty collection.</param>
        /// <param name="maxCount">The maximum element count. This must be greater than zero, and greater than or equal to the number of elements in <paramref name="collection"/>.</param>
        public AsyncProducerConsumerQueue(IEnumerable <T> collection, int maxCount)
        {
            if (maxCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxCount), "The maximum count must be greater than zero.");
            }
            _queue = collection == null ? new Queue <T>() : new Queue <T>(collection);
            if (maxCount < _queue.Count)
            {
                throw new ArgumentException("The maximum count cannot be less than the number of elements in the collection.", nameof(maxCount));
            }
            _maxCount = maxCount;

            _mutex = new AsyncLock();
            _completedOrNotFull  = new AsyncConditionVariable(_mutex);
            _completedOrNotEmpty = new AsyncConditionVariable(_mutex);
        }
Exemple #3
0
 public DebugView(AsyncConditionVariable cv)
 {
     _cv = cv;
 }
Exemple #4
0
 /// <summary>
 /// Constructs a new monitor.
 /// </summary>
 /// <param name="lockQueue">The wait queue used to manage waiters for the lock. This may be <c>null</c> to use a default (FIFO) queue.</param>
 /// <param name="conditionVariableQueue">The wait queue used to manage waiters for the signal. This may be <c>null</c> to use a default (FIFO) queue.</param>
 public AsyncMonitor(IAsyncWaitQueue <IDisposable> lockQueue, IAsyncWaitQueue <object> conditionVariableQueue)
 {
     _asyncLock         = new AsyncLock(lockQueue);
     _conditionVariable = new AsyncConditionVariable(_asyncLock, conditionVariableQueue);
 }