/// <summary>
        /// ParallelWorker
        /// </summary>
        /// <param name="workerCount"></param>
        /// <exception cref="ArgumentException"></exception>
        public ParallelWorker(int workerCount)
        {
            if (workerCount < 1)
            {
                throw new ArgumentException(nameof(workerCount));
            }

            this.syncRoot    = new object();
            this.capacity    = workerCount;
            this.idleWorkers = ImmutableHashSet <int> .Empty.Union(Enumerable.Range(0, workerCount));

            this.busyWorkers = ImmutableHashSet <int> .Empty;

            this.waitingWorkItems = new CancellableQueue <WaitingWorkItem>();
        }
        /// <summary>
        /// AsyncQueue
        /// </summary>
        /// <param name="capacity"></param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public AsyncQueue(int?capacity)
        {
            if (capacity.HasValue && capacity.Value < 1)
            {
                // ReSharper disable once NotResolvedInText
                throw new ArgumentOutOfRangeException("Capacity must be at least one");
            }

            this.syncRoot      = new object();
            this.capacity      = capacity;
            this.readPtr       = BigInteger.Zero;
            this.readLocked    = null;
            this.writeLocked   = null;
            this.eofSignaled   = false;
            this.items         = ImmutableList <T> .Empty;
            this.waitingReads  = new CancellableQueue <WaitingRead>();
            this.waitingWrites = new CancellableQueue <WaitingWrite>();
        }
Beispiel #3
0
 public IdleDetector()
 {
     syncRoot       = new object();
     referenceCount = 0;
     waiters        = new CancellableQueue <Waiter>();
 }