mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-20 22:14:34 -04:00
Reformat and apply Stylecop rules
This commit is contained in:
@@ -11,12 +11,15 @@ namespace NzbDrone.Common.TPL
|
||||
/// <summary>Whether the current thread is processing work items.</summary>
|
||||
[ThreadStatic]
|
||||
private static bool _currentThreadIsProcessingItems;
|
||||
|
||||
/// <summary>The list of tasks to be executed.</summary>
|
||||
private readonly LinkedList<Task> _tasks = new LinkedList<Task>(); // protected by lock(_tasks)
|
||||
private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
|
||||
|
||||
/// <summary>The maximum concurrency level allowed by this scheduler.</summary>
|
||||
private readonly int _maxDegreeOfParallelism;
|
||||
|
||||
/// <summary>Whether the scheduler is currently processing work items.</summary>
|
||||
private int _delegatesQueuedOrRunning = 0; // protected by lock(_tasks)
|
||||
private int _delegatesQueuedOrRunning = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the
|
||||
@@ -25,7 +28,11 @@ namespace NzbDrone.Common.TPL
|
||||
/// <param name="maxDegreeOfParallelism">The maximum degree of parallelism provided by this scheduler.</param>
|
||||
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
|
||||
{
|
||||
if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
|
||||
if (maxDegreeOfParallelism < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
|
||||
}
|
||||
|
||||
_maxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
}
|
||||
|
||||
@@ -78,11 +85,15 @@ namespace NzbDrone.Common.TPL
|
||||
}
|
||||
|
||||
// Execute the task we pulled out of the queue
|
||||
base.TryExecuteTask(item);
|
||||
TryExecuteTask(item);
|
||||
}
|
||||
}
|
||||
|
||||
// We're done processing items on the current thread
|
||||
finally { _currentThreadIsProcessingItems = false; }
|
||||
finally
|
||||
{
|
||||
_currentThreadIsProcessingItems = false;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@@ -93,13 +104,19 @@ namespace NzbDrone.Common.TPL
|
||||
protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||
{
|
||||
// If this thread isn't already processing a task, we don't support inlining
|
||||
if (!_currentThreadIsProcessingItems) return false;
|
||||
if (!_currentThreadIsProcessingItems)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the task was previously queued, remove it from the queue
|
||||
if (taskWasPreviouslyQueued) TryDequeue(task);
|
||||
if (taskWasPreviouslyQueued)
|
||||
{
|
||||
TryDequeue(task);
|
||||
}
|
||||
|
||||
// Try to run the task.
|
||||
return base.TryExecuteTask(task);
|
||||
return TryExecuteTask(task);
|
||||
}
|
||||
|
||||
/// <summary>Attempts to remove a previously scheduled task from the scheduler.</summary>
|
||||
@@ -107,7 +124,10 @@ namespace NzbDrone.Common.TPL
|
||||
/// <returns>Whether the task could be found and removed.</returns>
|
||||
protected sealed override bool TryDequeue(Task task)
|
||||
{
|
||||
lock (_tasks) return _tasks.Remove(task);
|
||||
lock (_tasks)
|
||||
{
|
||||
return _tasks.Remove(task);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets the maximum concurrency level supported by this scheduler.</summary>
|
||||
@@ -121,12 +141,21 @@ namespace NzbDrone.Common.TPL
|
||||
try
|
||||
{
|
||||
Monitor.TryEnter(_tasks, ref lockTaken);
|
||||
if (lockTaken) return _tasks.ToArray();
|
||||
else throw new NotSupportedException();
|
||||
if (lockTaken)
|
||||
{
|
||||
return _tasks.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockTaken) Monitor.Exit(_tasks);
|
||||
if (lockTaken)
|
||||
{
|
||||
Monitor.Exit(_tasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user