Only assign physicalCoreCount when needed.

This commit is contained in:
sunshineinabox 2023-07-08 07:46:43 -07:00
parent b5cb5c83fa
commit f9ec040ca5

View file

@ -57,6 +57,8 @@ namespace ARMeilleure.Translation
private Thread[] _backgroundTranslationThreads; private Thread[] _backgroundTranslationThreads;
private volatile int _threadCount; private volatile int _threadCount;
private static int physicalCoreCount;
// FIXME: Remove this once the init logic of the emulator will be redone. // FIXME: Remove this once the init logic of the emulator will be redone.
public static readonly ManualResetEvent IsReadyForTranslation = new(false); public static readonly ManualResetEvent IsReadyForTranslation = new(false);
@ -104,8 +106,6 @@ namespace ARMeilleure.Translation
public void Execute(State.ExecutionContext context, ulong address) public void Execute(State.ExecutionContext context, ulong address)
{ {
int physicalCoreCount = SystemInfo.GetPhysicalCoreCount();
if (Interlocked.Increment(ref _threadCount) == 1) if (Interlocked.Increment(ref _threadCount) == 1)
{ {
IsReadyForTranslation.WaitOne(); IsReadyForTranslation.WaitOne();
@ -120,6 +120,8 @@ namespace ARMeilleure.Translation
_ptc.Profiler.Start(); _ptc.Profiler.Start();
_ptc.Disable(); _ptc.Disable();
physicalCoreCount = SystemInfo.GetPhysicalCoreCount();
// Simple heuristic, should be user configurable in future. (1 for 4 core/ht or less, 2 for 6 core + ht // Simple heuristic, should be user configurable in future. (1 for 4 core/ht or less, 2 for 6 core + ht
// etc). All threads are normal priority except from the last, which just fills as much of the last core // etc). All threads are normal priority except from the last, which just fills as much of the last core