diff options
| -rw-r--r-- | src/core/hle/kernel/k_process.cpp | 26 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.h | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 11 |
3 files changed, 21 insertions, 24 deletions
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 265ac6fa1..85c506979 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp | |||
| @@ -146,6 +146,13 @@ ResultCode KProcess::Initialize(KProcess* process, Core::System& system, std::st | |||
| 146 | // Open a reference to the resource limit. | 146 | // Open a reference to the resource limit. |
| 147 | process->resource_limit->Open(); | 147 | process->resource_limit->Open(); |
| 148 | 148 | ||
| 149 | // Clear remaining fields. | ||
| 150 | process->num_running_threads = 0; | ||
| 151 | process->is_signaled = false; | ||
| 152 | process->exception_thread = nullptr; | ||
| 153 | process->is_suspended = false; | ||
| 154 | process->schedule_count = 0; | ||
| 155 | |||
| 149 | return ResultSuccess; | 156 | return ResultSuccess; |
| 150 | } | 157 | } |
| 151 | 158 | ||
| @@ -157,20 +164,17 @@ KResourceLimit* KProcess::GetResourceLimit() const { | |||
| 157 | return resource_limit; | 164 | return resource_limit; |
| 158 | } | 165 | } |
| 159 | 166 | ||
| 160 | void KProcess::IncrementThreadCount() { | 167 | void KProcess::IncrementRunningThreadCount() { |
| 161 | ASSERT(num_threads >= 0); | 168 | ASSERT(num_running_threads.load() >= 0); |
| 162 | num_created_threads++; | 169 | ++num_running_threads; |
| 163 | |||
| 164 | if (const auto count = ++num_threads; count > peak_num_threads) { | ||
| 165 | peak_num_threads = count; | ||
| 166 | } | ||
| 167 | } | 170 | } |
| 168 | 171 | ||
| 169 | void KProcess::DecrementThreadCount() { | 172 | void KProcess::DecrementRunningThreadCount() { |
| 170 | ASSERT(num_threads > 0); | 173 | ASSERT(num_running_threads.load() > 0); |
| 171 | 174 | ||
| 172 | if (const auto count = --num_threads; count == 0) { | 175 | if (const auto prev = num_running_threads--; prev == 1) { |
| 173 | LOG_WARNING(Kernel, "Process termination is not fully implemented."); | 176 | // TODO(bunnei): Process termination to be implemented when multiprocess is supported. |
| 177 | UNIMPLEMENTED_MSG("KProcess termination is not implemennted!"); | ||
| 174 | } | 178 | } |
| 175 | } | 179 | } |
| 176 | 180 | ||
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index c2a672021..38b446350 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h | |||
| @@ -235,8 +235,8 @@ public: | |||
| 235 | ++schedule_count; | 235 | ++schedule_count; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | void IncrementThreadCount(); | 238 | void IncrementRunningThreadCount(); |
| 239 | void DecrementThreadCount(); | 239 | void DecrementRunningThreadCount(); |
| 240 | 240 | ||
| 241 | void SetRunningThread(s32 core, KThread* thread, u64 idle_count) { | 241 | void SetRunningThread(s32 core, KThread* thread, u64 idle_count) { |
| 242 | running_threads[core] = thread; | 242 | running_threads[core] = thread; |
| @@ -473,9 +473,7 @@ private: | |||
| 473 | bool is_suspended{}; | 473 | bool is_suspended{}; |
| 474 | bool is_initialized{}; | 474 | bool is_initialized{}; |
| 475 | 475 | ||
| 476 | std::atomic<s32> num_created_threads{}; | 476 | std::atomic<u16> num_running_threads{}; |
| 477 | std::atomic<u16> num_threads{}; | ||
| 478 | u16 peak_num_threads{}; | ||
| 479 | 477 | ||
| 480 | std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{}; | 478 | std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{}; |
| 481 | std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{}; | 479 | std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{}; |
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index f42abb8a1..de3ffe0c7 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -215,7 +215,6 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s | |||
| 215 | 215 | ||
| 216 | parent = owner; | 216 | parent = owner; |
| 217 | parent->Open(); | 217 | parent->Open(); |
| 218 | parent->IncrementThreadCount(); | ||
| 219 | } | 218 | } |
| 220 | 219 | ||
| 221 | // Initialize thread context. | 220 | // Initialize thread context. |
| @@ -327,11 +326,6 @@ void KThread::Finalize() { | |||
| 327 | } | 326 | } |
| 328 | } | 327 | } |
| 329 | 328 | ||
| 330 | // Decrement the parent process's thread count. | ||
| 331 | if (parent != nullptr) { | ||
| 332 | parent->DecrementThreadCount(); | ||
| 333 | } | ||
| 334 | |||
| 335 | // Perform inherited finalization. | 329 | // Perform inherited finalization. |
| 336 | KSynchronizationObject::Finalize(); | 330 | KSynchronizationObject::Finalize(); |
| 337 | } | 331 | } |
| @@ -1011,7 +1005,7 @@ ResultCode KThread::Run() { | |||
| 1011 | if (IsUserThread() && IsSuspended()) { | 1005 | if (IsUserThread() && IsSuspended()) { |
| 1012 | this->UpdateState(); | 1006 | this->UpdateState(); |
| 1013 | } | 1007 | } |
| 1014 | owner->IncrementThreadCount(); | 1008 | owner->IncrementRunningThreadCount(); |
| 1015 | } | 1009 | } |
| 1016 | 1010 | ||
| 1017 | // Set our state and finish. | 1011 | // Set our state and finish. |
| @@ -1026,10 +1020,11 @@ ResultCode KThread::Run() { | |||
| 1026 | void KThread::Exit() { | 1020 | void KThread::Exit() { |
| 1027 | ASSERT(this == GetCurrentThreadPointer(kernel)); | 1021 | ASSERT(this == GetCurrentThreadPointer(kernel)); |
| 1028 | 1022 | ||
| 1029 | // Release the thread resource hint from parent. | 1023 | // Release the thread resource hint, running thread count from parent. |
| 1030 | if (parent != nullptr) { | 1024 | if (parent != nullptr) { |
| 1031 | parent->GetResourceLimit()->Release(Kernel::LimitableResource::Threads, 0, 1); | 1025 | parent->GetResourceLimit()->Release(Kernel::LimitableResource::Threads, 0, 1); |
| 1032 | resource_limit_release_hint = true; | 1026 | resource_limit_release_hint = true; |
| 1027 | parent->DecrementRunningThreadCount(); | ||
| 1033 | } | 1028 | } |
| 1034 | 1029 | ||
| 1035 | // Perform termination. | 1030 | // Perform termination. |