mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-28 02:14:08 +00:00
Ensure background translation threads exited before disposing JIT (#4874)
This commit is contained in:
parent
0a0675a7f6
commit
ba71141bdc
1 changed files with 19 additions and 3 deletions
|
@ -54,6 +54,7 @@ namespace ARMeilleure.Translation
|
||||||
internal TranslatorQueue Queue { get; }
|
internal TranslatorQueue Queue { get; }
|
||||||
internal IMemoryManager Memory { get; }
|
internal IMemoryManager Memory { get; }
|
||||||
|
|
||||||
|
private Thread[] _backgroundTranslationThreads;
|
||||||
private volatile int _threadCount;
|
private volatile int _threadCount;
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -127,18 +128,22 @@ namespace ARMeilleure.Translation
|
||||||
int unboundedThreadCount = Math.Max(1, (Environment.ProcessorCount - 6) / 3);
|
int unboundedThreadCount = Math.Max(1, (Environment.ProcessorCount - 6) / 3);
|
||||||
int threadCount = Math.Min(4, unboundedThreadCount);
|
int threadCount = Math.Min(4, unboundedThreadCount);
|
||||||
|
|
||||||
|
Thread[] backgroundTranslationThreads = new Thread[threadCount];
|
||||||
|
|
||||||
for (int i = 0; i < threadCount; i++)
|
for (int i = 0; i < threadCount; i++)
|
||||||
{
|
{
|
||||||
bool last = i != 0 && i == unboundedThreadCount - 1;
|
bool last = i != 0 && i == unboundedThreadCount - 1;
|
||||||
|
|
||||||
Thread backgroundTranslatorThread = new Thread(BackgroundTranslate)
|
backgroundTranslationThreads[i] = new Thread(BackgroundTranslate)
|
||||||
{
|
{
|
||||||
Name = "CPU.BackgroundTranslatorThread." + i,
|
Name = "CPU.BackgroundTranslatorThread." + i,
|
||||||
Priority = last ? ThreadPriority.Lowest : ThreadPriority.Normal
|
Priority = last ? ThreadPriority.Lowest : ThreadPriority.Normal
|
||||||
};
|
};
|
||||||
|
|
||||||
backgroundTranslatorThread.Start();
|
backgroundTranslationThreads[i].Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Interlocked.Exchange(ref _backgroundTranslationThreads, backgroundTranslationThreads);
|
||||||
}
|
}
|
||||||
|
|
||||||
Statistics.InitializeTimer();
|
Statistics.InitializeTimer();
|
||||||
|
@ -162,9 +167,20 @@ namespace ARMeilleure.Translation
|
||||||
|
|
||||||
if (Interlocked.Decrement(ref _threadCount) == 0)
|
if (Interlocked.Decrement(ref _threadCount) == 0)
|
||||||
{
|
{
|
||||||
|
Queue.Dispose();
|
||||||
|
|
||||||
|
Thread[] backgroundTranslationThreads = Interlocked.Exchange(ref _backgroundTranslationThreads, null);
|
||||||
|
|
||||||
|
if (backgroundTranslationThreads != null)
|
||||||
|
{
|
||||||
|
foreach (Thread thread in backgroundTranslationThreads)
|
||||||
|
{
|
||||||
|
thread.Join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ClearJitCache();
|
ClearJitCache();
|
||||||
|
|
||||||
Queue.Dispose();
|
|
||||||
Stubs.Dispose();
|
Stubs.Dispose();
|
||||||
FunctionTable.Dispose();
|
FunctionTable.Dispose();
|
||||||
CountTable.Dispose();
|
CountTable.Dispose();
|
||||||
|
|
Loading…
Reference in a new issue