From cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 20 Jan 2021 13:42:27 -0800 Subject: hle: kernel: Recode implementation of KThread to be more accurate. --- src/core/hle/kernel/process.h | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/core/hle/kernel/process.h') diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 917babfb4..11d78f3a8 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -217,6 +217,14 @@ public: return is_64bit_process; } + [[nodiscard]] bool IsSuspended() const { + return is_suspended; + } + + void SetSuspended(bool suspended) { + is_suspended = suspended; + } + /// Gets the total running time of the process instance in ticks. u64 GetCPUTimeTicks() const { return total_process_running_time_ticks; @@ -237,6 +245,33 @@ public: ++schedule_count; } + void IncrementThreadCount(); + void DecrementThreadCount(); + + void SetRunningThread(s32 core, KThread* thread, u64 idle_count) { + running_threads[core] = thread; + running_thread_idle_counts[core] = idle_count; + } + + void ClearRunningThread(KThread* thread) { + for (size_t i = 0; i < running_threads.size(); ++i) { + if (running_threads[i] == thread) { + running_threads[i] = nullptr; + } + } + } + + [[nodiscard]] KThread* GetRunningThread(s32 core) const { + return running_threads[core]; + } + + bool ReleaseUserException(KThread* thread); + + [[nodiscard]] KThread* GetPinnedThread(s32 core_id) const { + ASSERT(0 <= core_id && core_id < static_cast(Core::Hardware::NUM_CPU_CORES)); + return pinned_threads[core_id]; + } + /// Gets 8 bytes of random data for svcGetInfo RandomEntropy u64 GetRandomEntropy(std::size_t index) const { return random_entropy.at(index); @@ -310,6 +345,9 @@ public: void Finalize() override {} + void PinCurrentThread(); + void UnpinCurrentThread(); + /////////////////////////////////////////////////////////////////////////////////////////////// // Thread-local storage management @@ -320,6 +358,20 @@ public: void FreeTLSRegion(VAddr tls_address); private: + void PinThread(s32 core_id, KThread* thread) { + ASSERT(0 <= core_id && core_id < static_cast(Core::Hardware::NUM_CPU_CORES)); + ASSERT(thread != nullptr); + ASSERT(pinned_threads[core_id] == nullptr); + pinned_threads[core_id] = thread; + } + + void UnpinThread(s32 core_id, KThread* thread) { + ASSERT(0 <= core_id && core_id < static_cast(Core::Hardware::NUM_CPU_CORES)); + ASSERT(thread != nullptr); + ASSERT(pinned_threads[core_id] == thread); + pinned_threads[core_id] = nullptr; + } + /// Changes the process status. If the status is different /// from the current process status, then this will trigger /// a process signal. @@ -408,6 +460,17 @@ private: s64 schedule_count{}; bool is_signaled{}; + bool is_suspended{}; + + std::atomic num_created_threads{}; + std::atomic num_threads{}; + u16 peak_num_threads{}; + + std::array running_threads{}; + std::array running_thread_idle_counts{}; + std::array pinned_threads{}; + + KThread* exception_thread{}; /// System context Core::System& system; -- cgit v1.2.3