diff --git a/ChocolArm64/AThread.cs b/ChocolArm64/AThread.cs index 4fc79d5ef2..7b8360f8fe 100644 --- a/ChocolArm64/AThread.cs +++ b/ChocolArm64/AThread.cs @@ -18,8 +18,6 @@ namespace ChocolArm64 public event EventHandler WorkFinished; - public int ThreadId => ThreadState.ThreadId; - private int IsExecuting; public AThread(ATranslator Translator, AMemory Memory, long EntryPoint) diff --git a/ChocolArm64/Memory/AMemory.cs b/ChocolArm64/Memory/AMemory.cs index 1b4ff6fb19..566e6b54ce 100644 --- a/ChocolArm64/Memory/AMemory.cs +++ b/ChocolArm64/Memory/AMemory.cs @@ -41,7 +41,7 @@ namespace ChocolArm64.Memory } } - private Dictionary Monitors; + private Dictionary Monitors; private ConcurrentDictionary ObservedPages; @@ -53,7 +53,7 @@ namespace ChocolArm64.Memory public AMemory(IntPtr Ram) { - Monitors = new Dictionary(); + Monitors = new Dictionary(); ObservedPages = new ConcurrentDictionary(); @@ -75,7 +75,7 @@ namespace ChocolArm64.Memory { ClearExclusive(State); - Monitors.Remove(State.ThreadId); + Monitors.Remove(State); } } @@ -93,11 +93,11 @@ namespace ChocolArm64.Memory } } - if (!Monitors.TryGetValue(ThreadState.ThreadId, out ArmMonitor ThreadMon)) + if (!Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon)) { ThreadMon = new ArmMonitor(); - Monitors.Add(ThreadState.ThreadId, ThreadMon); + Monitors.Add(ThreadState, ThreadMon); } ThreadMon.Position = Position; @@ -113,7 +113,7 @@ namespace ChocolArm64.Memory Monitor.Enter(Monitors); - if (!Monitors.TryGetValue(ThreadState.ThreadId, out ArmMonitor ThreadMon)) + if (!Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon)) { return false; } @@ -130,7 +130,7 @@ namespace ChocolArm64.Memory public void ClearExclusiveForStore(AThreadState ThreadState) { - if (Monitors.TryGetValue(ThreadState.ThreadId, out ArmMonitor ThreadMon)) + if (Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon)) { ThreadMon.ExState = false; } @@ -142,7 +142,7 @@ namespace ChocolArm64.Memory { lock (Monitors) { - if (Monitors.TryGetValue(ThreadState.ThreadId, out ArmMonitor ThreadMon)) + if (Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon)) { ThreadMon.ExState = false; } diff --git a/ChocolArm64/State/AThreadState.cs b/ChocolArm64/State/AThreadState.cs index b26571b025..7b69d81714 100644 --- a/ChocolArm64/State/AThreadState.cs +++ b/ChocolArm64/State/AThreadState.cs @@ -40,9 +40,6 @@ namespace ChocolArm64.State public bool Zero; public bool Negative; - public int ProcessId; - public int ThreadId; - public bool Running { get; set; } public long TpidrEl0 { get; set; } diff --git a/Ryujinx.HLE/HOS/Kernel/KThread.cs b/Ryujinx.HLE/HOS/Kernel/KThread.cs index a4cb8a313d..171fefc519 100644 --- a/Ryujinx.HLE/HOS/Kernel/KThread.cs +++ b/Ryujinx.HLE/HOS/Kernel/KThread.cs @@ -33,18 +33,20 @@ namespace Ryujinx.HLE.HOS.Kernel public long LastPc { get; set; } - public int ThreadId => Thread.ThreadId; + public int ThreadId { get; private set; } public KThread( AThread Thread, Process Process, int ProcessorId, - int Priority) + int Priority, + int ThreadId) { this.Thread = Thread; this.Process = Process; this.ProcessorId = ProcessorId; this.IdealCore = ProcessorId; + this.ThreadId = ThreadId; MutexWaiters = new List(); diff --git a/Ryujinx.HLE/HOS/Kernel/SvcSystem.cs b/Ryujinx.HLE/HOS/Kernel/SvcSystem.cs index 2955245ac0..7cc1c8588e 100644 --- a/Ryujinx.HLE/HOS/Kernel/SvcSystem.cs +++ b/Ryujinx.HLE/HOS/Kernel/SvcSystem.cs @@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Kernel private void SvcExitProcess(AThreadState ThreadState) { - Device.System.ExitProcess(ThreadState.ProcessId); + Device.System.ExitProcess(Process.ProcessId); } private void SvcClearEvent(AThreadState ThreadState) diff --git a/Ryujinx.HLE/HOS/Process.cs b/Ryujinx.HLE/HOS/Process.cs index e11c265c39..b7ae914f70 100644 --- a/Ryujinx.HLE/HOS/Process.cs +++ b/Ryujinx.HLE/HOS/Process.cs @@ -194,18 +194,16 @@ namespace Ryujinx.HLE.HOS AThread CpuThread = new AThread(GetTranslator(), Memory, EntryPoint); - KThread Thread = new KThread(CpuThread, this, ProcessorId, Priority); + long Tpidr = GetFreeTls(); + + int ThreadId = (int)((Tpidr - MemoryManager.TlsIoRegionStart) / 0x200) + 1; + + KThread Thread = new KThread(CpuThread, this, ProcessorId, Priority, ThreadId); Thread.LastPc = EntryPoint; int Handle = HandleTable.OpenHandle(Thread); - long Tpidr = GetFreeTls(); - - int ThreadId = (int)((Tpidr - MemoryManager.TlsIoRegionStart) / 0x200) + 1; - - CpuThread.ThreadState.ProcessId = ProcessId; - CpuThread.ThreadState.ThreadId = ThreadId; CpuThread.ThreadState.CntfrqEl0 = TickFreq; CpuThread.ThreadState.Tpidr = Tpidr;