Queue multiple textures if we have room

Additionally, fix a potential bug where a thread is not running and does
not update the State to Progress, so we want to count them as active.
This commit is contained in:
nopjmp
2019-10-26 16:56:09 -05:00
parent 5ba7da70a9
commit b3d63cf2ef

View File

@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenMetaverse.Packets;
using OpenMetaverse.Assets;
@@ -466,21 +467,20 @@ namespace OpenMetaverse
while (_Running)
{
// find free slots
int pending = 0;
int active = 0;
TaskInfo nextTask = null;
var pendingTasks = new Queue<TaskInfo>();
lock (_Transfers)
{
foreach (KeyValuePair<UUID, TaskInfo> request in _Transfers)
foreach (var request in _Transfers)
{
switch (request.Value.State)
{
case TextureRequestState.Pending:
nextTask = request.Value;
++pending;
pendingTasks.Enqueue(request.Value);
break;
case TextureRequestState.Started:
case TextureRequestState.Progress:
++active;
break;
@@ -488,14 +488,15 @@ namespace OpenMetaverse
}
}
if (pending > 0 && active <= maxTextureRequests)
// NOTE: use TryDequeue once we can use .NET Standard 2.1
while (active <= maxTextureRequests && pendingTasks.Any())
{
var nextTask = pendingTasks.Dequeue();
nextTask.State = TextureRequestState.Started;
//Logger.DebugLog(String.Format("Sending Worker thread new download request {0}", slot));
ThreadPool.QueueUserWorkItem(TextureRequestDoWork, nextTask);
continue;
++active;
}
// Queue was empty or all download slots are inuse, let's give up some CPU time