/// <summary>Initialies the ConcurrentExclusiveInterleave.</summary> /// <param name="targetScheduler">The target scheduler on which this interleave should execute.</param> /// <param name="exclusiveProcessingIncludesChildren">Whether the exclusive processing of a task should include all of its children as well.</param> public ConcurrentExclusiveInterleave(TaskScheduler targetScheduler, bool exclusiveProcessingIncludesChildren) { // A scheduler must be provided if (targetScheduler == null) throw new ArgumentNullException("targetScheduler"); // Create the state for this interleave _internalLock = new object(); _exclusiveProcessingIncludesChildren = exclusiveProcessingIncludesChildren; _parallelOptions = new ParallelOptions() { TaskScheduler = targetScheduler }; _concurrentTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue<Task>(), targetScheduler.MaximumConcurrencyLevel); _exclusiveTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue<Task>(), 1); }
/// <summary>Initialies the ConcurrentExclusiveInterleave.</summary> /// <param name="targetScheduler">The target scheduler on which this interleave should execute.</param> /// <param name="exclusiveProcessingIncludesChildren">Whether the exclusive processing of a task should include all of its children as well.</param> public ConcurrentExclusiveInterleave(TaskScheduler targetScheduler, bool exclusiveProcessingIncludesChildren) { if (targetScheduler == null) { throw new ArgumentNullException("targetScheduler"); } this._internalLock = new object(); this._exclusiveProcessingIncludesChildren = exclusiveProcessingIncludesChildren; ParallelOptions options = new ParallelOptions { TaskScheduler = targetScheduler }; this._parallelOptions = options; this._concurrentTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue <Task>(), targetScheduler.MaximumConcurrencyLevel); this._exclusiveTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue <Task>(), 1); }
/// <summary>Initializes the ConcurrentExclusiveInterleave.</summary> /// <param name="targetScheduler">The target scheduler on which this interleave should execute.</param> /// <param name="exclusiveProcessingIncludesChildren">Whether the exclusive processing of a task should include all of its children as well.</param> public ConcurrentExclusiveInterleave(TaskScheduler targetScheduler, bool exclusiveProcessingIncludesChildren) { // A scheduler must be provided if (targetScheduler == null) { throw new ArgumentNullException("targetScheduler"); } // Create the state for this interleave internalLock = new object(); this.exclusiveProcessingIncludesChildren = exclusiveProcessingIncludesChildren; parallelOptions = new ParallelOptions { TaskScheduler = targetScheduler }; concurrentTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue <Task>(), targetScheduler.MaximumConcurrencyLevel); exclusiveTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, new Queue <Task>(), 1); }
/// <summary> /// Initializes the ConcurrentExclusiveSchedulerPair to target the specified scheduler with a maximum /// concurrency level and a maximum number of scheduled tasks that may be processed as a unit. /// </summary> /// <param name="taskScheduler">The target scheduler on which this pair should execute.</param> /// <param name="maxConcurrencyLevel">The maximum number of tasks to run concurrently.</param> /// <param name="maxItemsPerTask">The maximum number of tasks to process for each underlying scheduled task used by the pair.</param> public ConcurrentExclusiveSchedulerPair(TaskScheduler taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask) { // Validate arguments if (taskScheduler == null) { throw new ArgumentNullException("taskScheduler"); } if (maxConcurrencyLevel == 0 || maxConcurrencyLevel < -1) { throw new ArgumentOutOfRangeException("maxConcurrencyLevel"); } if (maxItemsPerTask == 0 || maxItemsPerTask < -1) { throw new ArgumentOutOfRangeException("maxItemsPerTask"); } Contract.EndContractBlock(); // Store configuration m_underlyingTaskScheduler = taskScheduler; m_maxConcurrencyLevel = maxConcurrencyLevel; m_maxItemsPerTask = maxItemsPerTask; // Downgrade to the underlying scheduler's max degree of parallelism if it's lower than the user-supplied level int mcl = taskScheduler.MaximumConcurrencyLevel; if (mcl > 0 && mcl < m_maxConcurrencyLevel) { m_maxConcurrencyLevel = mcl; } // Treat UNLIMITED_PROCESSING/-1 for both MCL and MIPT as the biggest possible value so that we don't // have to special case UNLIMITED_PROCESSING later on in processing. if (m_maxConcurrencyLevel == UNLIMITED_PROCESSING) { m_maxConcurrencyLevel = Int32.MaxValue; } if (m_maxItemsPerTask == UNLIMITED_PROCESSING) { m_maxItemsPerTask = Int32.MaxValue; } // Create the concurrent/exclusive schedulers for this pair m_exclusiveTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, 1, ProcessingMode.ProcessingExclusiveTask); m_concurrentTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, m_maxConcurrencyLevel, ProcessingMode.ProcessingConcurrentTasks); }
// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. private void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. if (_taskExecuting != null) { _taskExecuting.Dispose(); } if (_concurrentTaskScheduler != null) { _concurrentTaskScheduler.Dispose(); } if (_exclusiveTaskScheduler != null) { _exclusiveTaskScheduler.Dispose(); } } // Call the appropriate methods to clean up // unmanaged resources here. _taskExecuting = null; _concurrentTaskScheduler = null; _exclusiveTaskScheduler = null; // Note disposing has been done. disposed = true; } }
/// <summary>Initializes the debug view.</summary> /// <param name="scheduler">The scheduler being debugged.</param> public DebugView(ConcurrentExclusiveTaskScheduler scheduler) { Contract.Requires(scheduler != null, "Need a scheduler with which to construct the debug view."); m_taskScheduler = scheduler; }
/// <summary>Initializes the debug view.</summary> /// <param name="scheduler">The scheduler being debugged.</param> public DebugView(ConcurrentExclusiveTaskScheduler scheduler) { Debug.Assert(scheduler != null, "Need a scheduler with which to construct the debug view."); m_taskScheduler = scheduler; }