mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 04:59:35 -07:00
Fixed: Unnecessary idle cpu usage
(cherry picked from commit 5a69801877eb72899dd9867c39a1b88b7114fe5b) (cherry picked from commit 4eb6cb9daee11cf473d063e95b9713375c986d09)
This commit is contained in:
parent
1dc623cb0c
commit
c855119c6f
2 changed files with 37 additions and 2 deletions
|
@ -23,6 +23,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
lock (_mutex)
|
lock (_mutex)
|
||||||
{
|
{
|
||||||
_items.Add(item);
|
_items.Add(item);
|
||||||
|
|
||||||
|
Monitor.PulseAll(_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +70,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
{
|
{
|
||||||
_items.Remove(command);
|
_items.Remove(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Monitor.PulseAll(_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +87,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
{
|
{
|
||||||
_items.Remove(command);
|
_items.Remove(command);
|
||||||
rval = true;
|
rval = true;
|
||||||
|
|
||||||
|
Monitor.PulseAll(_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,14 +108,39 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
|
|
||||||
public IEnumerable<CommandModel> GetConsumingEnumerable(CancellationToken cancellationToken)
|
public IEnumerable<CommandModel> GetConsumingEnumerable(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
cancellationToken.Register(PulseAllConsumers);
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
if (TryGet(out var command))
|
CommandModel command = null;
|
||||||
|
|
||||||
|
lock (_mutex)
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGet(out command))
|
||||||
|
{
|
||||||
|
Monitor.Wait(_mutex);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command != null)
|
||||||
{
|
{
|
||||||
yield return command;
|
yield return command;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Thread.Sleep(10);
|
public void PulseAllConsumers()
|
||||||
|
{
|
||||||
|
// Signal all consumers to reevaluate cancellation token
|
||||||
|
lock (_mutex)
|
||||||
|
{
|
||||||
|
Monitor.PulseAll(_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
public void Complete(CommandModel command, string message)
|
public void Complete(CommandModel command, string message)
|
||||||
{
|
{
|
||||||
Update(command, CommandStatus.Completed, message);
|
Update(command, CommandStatus.Completed, message);
|
||||||
|
|
||||||
|
_commandQueue.PulseAllConsumers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fail(CommandModel command, string message, Exception e)
|
public void Fail(CommandModel command, string message, Exception e)
|
||||||
|
@ -195,6 +197,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||||
command.Exception = e.ToString();
|
command.Exception = e.ToString();
|
||||||
|
|
||||||
Update(command, CommandStatus.Failed, message);
|
Update(command, CommandStatus.Failed, message);
|
||||||
|
|
||||||
|
_commandQueue.PulseAllConsumers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Requeue()
|
public void Requeue()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue