/// <summary> /// Initializes a new instance of <see cref="BlockingThreadPoolTaskScheduler"/> using <paramref name="boundedCapacity"/> as the bounded capacity with an overridden thread pool and monitor class. /// </summary> /// <param name="boundedCapacity">The bounded size of the task queue.</param> /// <param name="threadPool">The thread pool implementation on which to schedule tasks.</param> /// <param name="monitor">The monitor implementation used to synchronize object access.</param> internal BlockingThreadPoolTaskScheduler(Int32 boundedCapacity, IQueueUserWorkItems threadPool, ISynchronizeAccess monitor) { Verify.GreaterThan(0, boundedCapacity, nameof(boundedCapacity)); Verify.NotNull(threadPool, nameof(threadPool)); Log.Trace("BoundedCapacity={0}, MaximumConcurrencyLevel={1}", boundedCapacity, MaximumConcurrencyLevel); this.monitor = monitor; this.threadPool = threadPool; this.boundedCapacity = boundedCapacity; }
/// <summary> /// Initializes a new instance of <see cref="PartitionedTaskScheduler"/> with the specified maximum concurrency level of <see cref="maximumConcurrencyLevel"/> /// and a bounded capacity of <see cref="boundedCapacity"/>. /// </summary> /// <param name="hash">The <see cref="Task"/> hash function used to determine the executor partition.</param> /// <param name="maximumConcurrencyLevel">The maximum number of concurrently executing tasks.</param> /// <param name="boundedCapacity">The bounded size of the task queue.</param> /// <param name="threadPool">The thread pool implementation on which to schedule tasks.</param> /// <param name="monitor">The monitor implementation used to synchronize object access.</param> internal PartitionedTaskScheduler(Func <Task, Object> hash, Int32 maximumConcurrencyLevel, Int32 boundedCapacity, IQueueUserWorkItems threadPool, ISynchronizeAccess monitor) { Verify.NotNull(hash, nameof(hash)); Verify.NotNull(monitor, nameof(monitor)); Verify.NotNull(threadPool, nameof(threadPool)); Verify.GreaterThan(0, boundedCapacity, nameof(boundedCapacity)); Verify.GreaterThan(0, maximumConcurrencyLevel, nameof(maximumConcurrencyLevel)); Verify.LessThanOrEqual(MaximumWorkerThreads, maximumConcurrencyLevel, nameof(maximumConcurrencyLevel)); Log.Trace("BoundedCapacity={0}, MaximumConcurrencyLevel={1}", boundedCapacity, maximumConcurrencyLevel); this.monitor = monitor; this.threadPool = threadPool; this.boundedCapacity = boundedCapacity; this.maximumConcurrencyLevel = maximumConcurrencyLevel; this.partitionHash = task => Math.Abs((hash(task) ?? 0).GetHashCode()) % maximumConcurrencyLevel; }
/// <summary> /// Initializes a new instance of <see cref="PartitionedTaskScheduler"/> with the specified maximum concurrency level of <see cref="maximumConcurrencyLevel"/> /// and a bounded capacity of <see cref="boundedCapacity"/>. /// </summary> /// <param name="hash">The <see cref="Task"/> hash function used to determine the executor partition.</param> /// <param name="maximumConcurrencyLevel">The maximum number of concurrently executing tasks.</param> /// <param name="boundedCapacity">The bounded size of the task queue.</param> /// <param name="threadPool">The thread pool implementation on which to schedule tasks.</param> /// <param name="monitor">The monitor implementation used to synchronize object access.</param> internal PartitionedTaskScheduler(Func<Task, Object> hash, Int32 maximumConcurrencyLevel, Int32 boundedCapacity, IQueueUserWorkItems threadPool, ISynchronizeAccess monitor) { Verify.NotNull(hash, nameof(hash)); Verify.NotNull(monitor, nameof(monitor)); Verify.NotNull(threadPool, nameof(threadPool)); Verify.GreaterThan(0, boundedCapacity, nameof(boundedCapacity)); Verify.GreaterThan(0, maximumConcurrencyLevel, nameof(maximumConcurrencyLevel)); Verify.LessThanOrEqual(MaximumWorkerThreads, maximumConcurrencyLevel, nameof(maximumConcurrencyLevel)); Log.Trace("BoundedCapacity={0}, MaximumConcurrencyLevel={1}", boundedCapacity, maximumConcurrencyLevel); this.monitor = monitor; this.threadPool = threadPool; this.boundedCapacity = boundedCapacity; this.maximumConcurrencyLevel = maximumConcurrencyLevel; this.partitionHash = task => Math.Abs((hash(task) ?? 0).GetHashCode()) % maximumConcurrencyLevel; }