diff options
| author | 2021-01-20 13:42:27 -0800 | |
|---|---|---|
| committer | 2021-01-28 21:42:26 -0800 | |
| commit | cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce (patch) | |
| tree | 987f6cb5d3f1955dc88f5ac2c1d5c1329d787fc4 /src/core/hle/kernel/process.cpp | |
| parent | kernel: svc_types: Add ThreadActivity. (diff) | |
| download | yuzu-cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce.tar.gz yuzu-cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce.tar.xz yuzu-cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce.zip | |
hle: kernel: Recode implementation of KThread to be more accurate.
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 819e275ff..9f4583b49 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -136,6 +136,23 @@ std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const { | |||
| 136 | return resource_limit; | 136 | return resource_limit; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | void Process::IncrementThreadCount() { | ||
| 140 | ASSERT(num_threads >= 0); | ||
| 141 | ++num_created_threads; | ||
| 142 | |||
| 143 | if (const auto count = ++num_threads; count > peak_num_threads) { | ||
| 144 | peak_num_threads = count; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | void Process::DecrementThreadCount() { | ||
| 149 | ASSERT(num_threads > 0); | ||
| 150 | |||
| 151 | if (const auto count = --num_threads; count == 0) { | ||
| 152 | UNIMPLEMENTED_MSG("Process termination is not implemented!"); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 139 | u64 Process::GetTotalPhysicalMemoryAvailable() const { | 156 | u64 Process::GetTotalPhysicalMemoryAvailable() const { |
| 140 | const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + | 157 | const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + |
| 141 | page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + | 158 | page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + |
| @@ -161,6 +178,61 @@ u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const { | |||
| 161 | return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); | 178 | return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); |
| 162 | } | 179 | } |
| 163 | 180 | ||
| 181 | bool Process::ReleaseUserException(KThread* thread) { | ||
| 182 | KScopedSchedulerLock sl{kernel}; | ||
| 183 | |||
| 184 | if (exception_thread == thread) { | ||
| 185 | exception_thread = nullptr; | ||
| 186 | |||
| 187 | // Remove waiter thread. | ||
| 188 | s32 num_waiters{}; | ||
| 189 | KThread* next = thread->RemoveWaiterByKey( | ||
| 190 | std::addressof(num_waiters), | ||
| 191 | reinterpret_cast<uintptr_t>(std::addressof(exception_thread))); | ||
| 192 | if (next != nullptr) { | ||
| 193 | if (next->GetState() == ThreadState::Waiting) { | ||
| 194 | next->SetState(ThreadState::Runnable); | ||
| 195 | } else { | ||
| 196 | KScheduler::SetSchedulerUpdateNeeded(kernel); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | return true; | ||
| 201 | } else { | ||
| 202 | return false; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | |||
| 206 | void Process::PinCurrentThread() { | ||
| 207 | ASSERT(kernel.GlobalSchedulerContext().IsLocked()); | ||
| 208 | |||
| 209 | // Get the current thread. | ||
| 210 | const s32 core_id = GetCurrentCoreId(kernel); | ||
| 211 | KThread* cur_thread = GetCurrentThreadPointer(kernel); | ||
| 212 | |||
| 213 | // Pin it. | ||
| 214 | PinThread(core_id, cur_thread); | ||
| 215 | cur_thread->Pin(); | ||
| 216 | |||
| 217 | // An update is needed. | ||
| 218 | KScheduler::SetSchedulerUpdateNeeded(kernel); | ||
| 219 | } | ||
| 220 | |||
| 221 | void Process::UnpinCurrentThread() { | ||
| 222 | ASSERT(kernel.GlobalSchedulerContext().IsLocked()); | ||
| 223 | |||
| 224 | // Get the current thread. | ||
| 225 | const s32 core_id = GetCurrentCoreId(kernel); | ||
| 226 | KThread* cur_thread = GetCurrentThreadPointer(kernel); | ||
| 227 | |||
| 228 | // Unpin it. | ||
| 229 | cur_thread->Unpin(); | ||
| 230 | UnpinThread(core_id, cur_thread); | ||
| 231 | |||
| 232 | // An update is needed. | ||
| 233 | KScheduler::SetSchedulerUpdateNeeded(kernel); | ||
| 234 | } | ||
| 235 | |||
| 164 | void Process::RegisterThread(const KThread* thread) { | 236 | void Process::RegisterThread(const KThread* thread) { |
| 165 | thread_list.push_back(thread); | 237 | thread_list.push_back(thread); |
| 166 | } | 238 | } |
| @@ -278,7 +350,7 @@ void Process::PrepareForTermination() { | |||
| 278 | ASSERT_MSG(thread->GetState() == ThreadState::Waiting, | 350 | ASSERT_MSG(thread->GetState() == ThreadState::Waiting, |
| 279 | "Exiting processes with non-waiting threads is currently unimplemented"); | 351 | "Exiting processes with non-waiting threads is currently unimplemented"); |
| 280 | 352 | ||
| 281 | thread->Stop(); | 353 | thread->Exit(); |
| 282 | } | 354 | } |
| 283 | }; | 355 | }; |
| 284 | 356 | ||