fix: Game Boost no longer ignores a game that reuses a just-rejected PID for 30 s
The memory of a rejected foreground process was keyed by PID only; it now also compares the process start time. Found by the independent Codex review.
This commit is contained in:
committed by
Prime Build
parent
940d83ca64
commit
88bb2ec1a9
@@ -240,7 +240,7 @@ namespace ThreadPilot.Services
|
||||
|
||||
// Set by StopAsync: a tick already queued when the timer was disposed must not begin a session.
|
||||
private bool stopped;
|
||||
private (int ProcessId, long Timestamp)? rejectedForeground;
|
||||
private (int ProcessId, long StartTicks, long Timestamp)? rejectedForeground;
|
||||
private GameSession? session;
|
||||
private IGameProcessHandle? gameHandle;
|
||||
private GameBoostDecision? cachedDecision;
|
||||
@@ -454,8 +454,11 @@ namespace ThreadPilot.Services
|
||||
|
||||
// The browser or desktop usually stays in front for minutes: building its full process model every
|
||||
// 3 s only to reject it again costs ~8 process queries and a window enumeration per tick.
|
||||
// Keyed by start time too: Windows soon reuses the PID of an exited process, possibly for a game.
|
||||
this.processProbe.TryGetIdentity(processId, out var foregroundStartTicks, out _);
|
||||
if (this.rejectedForeground is { } rejected
|
||||
&& rejected.ProcessId == processId
|
||||
&& rejected.StartTicks == foregroundStartTicks
|
||||
&& this.timeProvider.GetElapsedTime(rejected.Timestamp) < RejectedForegroundMemory)
|
||||
{
|
||||
return;
|
||||
@@ -468,7 +471,7 @@ namespace ThreadPilot.Services
|
||||
// Remembered only when the path was readable: a game just starting may not expose it yet.
|
||||
if (!string.IsNullOrEmpty(game.ExecutablePath))
|
||||
{
|
||||
this.rejectedForeground = (processId, this.timeProvider.GetTimestamp());
|
||||
this.rejectedForeground = (processId, foregroundStartTicks, this.timeProvider.GetTimestamp());
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -61,6 +61,24 @@ namespace ThreadPilot.Core.Tests
|
||||
Assert.All(this.processes.CpuSets.Values, Assert.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RejectedPid_ReusedByAGame_StartsASessionAtTheNextTick()
|
||||
{
|
||||
// The 30 s memory of a rejected foreground process was keyed by PID only.
|
||||
this.processes.Add(700, "notepad", @"C:\Windows\notepad.exe");
|
||||
this.foregroundPid = 700;
|
||||
using var service = this.CreateService();
|
||||
await service.TickAsync();
|
||||
Assert.Null(service.ActiveGameName);
|
||||
|
||||
this.processes.Add(700, "Game2", @"D:\SteamLibrary\steamapps\common\Game2\Game2.exe");
|
||||
this.processes.Restart(700);
|
||||
this.clock.Advance(TimeSpan.FromSeconds(3));
|
||||
await service.TickAsync();
|
||||
|
||||
Assert.Equal("Game2", service.ActiveGameName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NonGameForeground_IsNotReexaminedEveryTick_ButIsAfterAWhile()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user