This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 425c9d3ec5ddc4dc710233f6f9dbb451ffa65dc1 Author: Shad Storhaug <[email protected]> AuthorDate: Thu Dec 9 04:18:43 2021 +0700 Lucene.Net.Support.Threading.LimitedConcurrencyLevelTaskScheduler: Added Shutdown() method to prevent new work from being queued. --- .../Threading/LimitedConcurrencyLevelTaskScheduler.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs b/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs index ce807e4..0717e95 100644 --- a/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs +++ b/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs @@ -48,6 +48,7 @@ Framework or Silverlight), or Microsoft application platform (such as Microsoft Office or Microsoft Dynamics). */ +using J2N.Threading.Atomic; using System; using System.Collections.Generic; using System.Threading; @@ -63,6 +64,8 @@ namespace Lucene.Net.Support.Threading /// </summary> internal class LimitedConcurrencyLevelTaskScheduler : TaskScheduler { + private readonly AtomicBoolean shutDown = new AtomicBoolean(false); + // Indicates whether the current thread is processing work items. [ThreadStatic] private static bool _currentThreadIsProcessingItems; @@ -86,6 +89,9 @@ namespace Lucene.Net.Support.Threading // Queues a task to the scheduler. protected sealed override void QueueTask(Task task) { + // Don't queue any more work. + if (shutDown) return; + // Add the task to the list of tasks to be processed. If there aren't enough // delegates currently queued or running to process tasks, schedule another. UninterruptableMonitor.Enter(_tasks); @@ -201,5 +207,11 @@ namespace Lucene.Net.Support.Threading if (lockTaken) UninterruptableMonitor.Exit(_tasks); } } + + // Stops this TaskScheduler from queuing new tasks. + public void Shutdown() + { + shutDown.Value = true; + } } }
