mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-28 18:04:47 +00:00
Fix ComputerThread not updating the minimumVirtualRuntime
We attempted to simplify this 0bfb7049b0
,
but that change now means that minimumVirtualRuntime is not updated. As
a result, new tasks will have a runtime of 0 when the queue is empty.
This commit is contained in:
parent
e46f09a939
commit
bd28955c8e
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.util.ThreadUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -205,7 +206,7 @@ public class ComputerThread
|
||||
if( executor.onComputerQueue ) throw new IllegalStateException( "Cannot queue already queued executor" );
|
||||
executor.onComputerQueue = true;
|
||||
|
||||
updateRuntimes();
|
||||
updateRuntimes( null );
|
||||
|
||||
// We're not currently on the queue, so update its current execution time to
|
||||
// ensure its at least as high as the minimum.
|
||||
@ -241,7 +242,7 @@ public class ComputerThread
|
||||
*
|
||||
* This is called before queueing tasks, to ensure that {@link #minimumVirtualRuntime} is up-to-date.
|
||||
*/
|
||||
private static void updateRuntimes()
|
||||
private static void updateRuntimes( @Nullable ComputerExecutor current )
|
||||
{
|
||||
long minRuntime = Long.MAX_VALUE;
|
||||
|
||||
@ -249,12 +250,11 @@ public class ComputerThread
|
||||
if( !computerQueue.isEmpty() ) minRuntime = computerQueue.first().virtualRuntime;
|
||||
|
||||
// Update all the currently executing tasks
|
||||
long now = System.nanoTime();
|
||||
int tasks = 1 + computerQueue.size();
|
||||
TaskRunner[] currentRunners = runners;
|
||||
if( currentRunners != null )
|
||||
{
|
||||
long now = System.nanoTime();
|
||||
int tasks = 1 + computerQueue.size();
|
||||
|
||||
for( TaskRunner runner : currentRunners )
|
||||
{
|
||||
if( runner == null ) continue;
|
||||
@ -268,6 +268,12 @@ public class ComputerThread
|
||||
}
|
||||
}
|
||||
|
||||
// And update the most recently executed one (if set).
|
||||
if( current != null )
|
||||
{
|
||||
minRuntime = Math.min( minRuntime, current.virtualRuntime += (now - current.vRuntimeStart) / tasks );
|
||||
}
|
||||
|
||||
if( minRuntime > minimumVirtualRuntime && minRuntime < Long.MAX_VALUE )
|
||||
{
|
||||
minimumVirtualRuntime = minRuntime;
|
||||
@ -296,9 +302,7 @@ public class ComputerThread
|
||||
computerLock.lock();
|
||||
try
|
||||
{
|
||||
// Update the virtual runtime of this task.
|
||||
long now = System.nanoTime();
|
||||
executor.virtualRuntime += (now - executor.vRuntimeStart) / (1 + computerQueue.size());
|
||||
updateRuntimes( executor );
|
||||
|
||||
// If we've no more tasks, just return.
|
||||
if( !executor.afterWork() ) return;
|
||||
|
Loading…
Reference in New Issue
Block a user