diff options
author | bunnei <bunneidev@gmail.com> | 2021-01-20 13:42:27 -0800 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-01-28 21:42:26 -0800 |
commit | cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce (patch) | |
tree | 987f6cb5d3f1955dc88f5ac2c1d5c1329d787fc4 /src/core/hle/kernel/process.h | |
parent | 14703384582dbd7ba53970e1b60eae37235dce8a (diff) |
hle: kernel: Recode implementation of KThread to be more accurate.
Diffstat (limited to 'src/core/hle/kernel/process.h')
-rw-r--r-- | src/core/hle/kernel/process.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 917babfb40..11d78f3a8d 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<s32>(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<s32>(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<s32>(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<s32> num_created_threads{}; + std::atomic<u16> num_threads{}; + u16 peak_num_threads{}; + + std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{}; + std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{}; + std::array<KThread*, Core::Hardware::NUM_CPU_CORES> pinned_threads{}; + + KThread* exception_thread{}; /// System context Core::System& system; |