|
|
@@ -8,13 +8,13 @@ using Ryujinx.Common.Logging;
|
|
|
using System;
|
|
|
using System.Buffers.Binary;
|
|
|
using System.Collections.Concurrent;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
using System.IO.Compression;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Security.Cryptography;
|
|
|
using System.Threading;
|
|
|
-using System.Threading.Tasks;
|
|
|
|
|
|
namespace ARMeilleure.Translation.PTC
|
|
|
{
|
|
|
@@ -664,35 +664,50 @@ namespace ARMeilleure.Translation.PTC
|
|
|
|
|
|
ThreadPool.QueueUserWorkItem(TranslationLogger, profiledFuncsToTranslate.Count);
|
|
|
|
|
|
- int maxDegreeOfParallelism = (Environment.ProcessorCount * 3) / 4;
|
|
|
-
|
|
|
- Parallel.ForEach(profiledFuncsToTranslate, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, (item, state) =>
|
|
|
+ void TranslateFuncs()
|
|
|
{
|
|
|
- ulong address = item.Key;
|
|
|
+ while (profiledFuncsToTranslate.TryDequeue(out var item))
|
|
|
+ {
|
|
|
+ ulong address = item.address;
|
|
|
|
|
|
- Debug.Assert(PtcProfiler.IsAddressInStaticCodeRange(address));
|
|
|
+ Debug.Assert(PtcProfiler.IsAddressInStaticCodeRange(address));
|
|
|
|
|
|
- TranslatedFunction func = Translator.Translate(memory, jumpTable, address, item.Value.mode, item.Value.highCq);
|
|
|
+ TranslatedFunction func = Translator.Translate(memory, jumpTable, address, item.mode, item.highCq);
|
|
|
|
|
|
- bool isAddressUnique = funcs.TryAdd(address, func);
|
|
|
+ bool isAddressUnique = funcs.TryAdd(address, func);
|
|
|
|
|
|
- Debug.Assert(isAddressUnique, $"The address 0x{address:X16} is not unique.");
|
|
|
+ Debug.Assert(isAddressUnique, $"The address 0x{address:X16} is not unique.");
|
|
|
|
|
|
- if (func.HighCq)
|
|
|
- {
|
|
|
- jumpTable.RegisterFunction(address, func);
|
|
|
+ Interlocked.Increment(ref _translateCount);
|
|
|
+
|
|
|
+ if (State != PtcState.Enabled)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ int maxDegreeOfParallelism = (Environment.ProcessorCount * 3) / 4;
|
|
|
|
|
|
- Interlocked.Increment(ref _translateCount);
|
|
|
+ List<Thread> threads = new List<Thread>();
|
|
|
|
|
|
- if (State != PtcState.Enabled)
|
|
|
- {
|
|
|
- state.Stop();
|
|
|
- }
|
|
|
- });
|
|
|
+ for (int i = 0; i < maxDegreeOfParallelism; i++)
|
|
|
+ {
|
|
|
+ Thread thread = new Thread(TranslateFuncs);
|
|
|
+ thread.IsBackground = true;
|
|
|
+
|
|
|
+ threads.Add(thread);
|
|
|
+ }
|
|
|
+
|
|
|
+ threads.ForEach((thread) => thread.Start());
|
|
|
+ threads.ForEach((thread) => thread.Join());
|
|
|
+
|
|
|
+ threads.Clear();
|
|
|
|
|
|
_loggerEvent.Set();
|
|
|
|
|
|
+ Translator.ResetPools();
|
|
|
+
|
|
|
PtcJumpTable.Initialize(jumpTable);
|
|
|
|
|
|
PtcJumpTable.ReadJumpTable(jumpTable);
|