Skip to content

Commit d5c0d64

Browse files
committed
Use interruptable sleep.
Was suggested in PR review. Avoids the extra counter.
1 parent 115325f commit d5c0d64

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Source/RunActivity/Processes/ProcessState.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,11 @@ public void WaitTillFinished()
9595
DebugFileStream.Write("{0},WTF-\n", DateTime.Now.Ticks);
9696
#endif
9797
}
98+
99+
/// <summary>Wait for the specified number of milliseconds, unless termination is signalled.</summary>
100+
public void Sleep(int milliseconds)
101+
{
102+
TerminateEvent.WaitOne(milliseconds);
103+
}
98104
}
99105
}

Source/RunActivity/Viewer3D/Processes/HostProcess.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public class HostProcess
6262
readonly Game Game;
6363
readonly Thread Thread;
6464

65-
private const int DoHostTime = 10000;
66-
private const int SleepTime = 100; // must be short enough for timely termination
67-
private const uint DoHostInterval = DoHostTime / SleepTime;
65+
private const int SleepTime = 10000;
6866

6967
public HostProcess(Game game)
7068
{
@@ -93,18 +91,13 @@ void HostThread()
9391
GlobalMemoryStatusEx(memoryStatus);
9492
CPUMemoryVirtualLimit = Math.Min(memoryStatus.TotalVirtual, memoryStatus.TotalPhysical);
9593

96-
uint sleepCount = 0;
9794
while (true)
9895
{
99-
Thread.Sleep(SleepTime);
96+
State.Sleep(SleepTime);
10097
if (State.Terminated)
10198
break;
102-
if (sleepCount % DoHostInterval == 0)
103-
{
104-
if (!DoHost())
105-
return;
106-
}
107-
sleepCount++;
99+
if (!DoHost())
100+
return;
108101
}
109102
}
110103

0 commit comments

Comments
 (0)