diff options
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 16d9b9e36..36222d45f 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -129,6 +129,11 @@ static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { | |||
| 129 | thread->mutex_wait_address = 0; | 129 | thread->mutex_wait_address = 0; |
| 130 | thread->condvar_wait_address = 0; | 130 | thread->condvar_wait_address = 0; |
| 131 | thread->wait_handle = 0; | 131 | thread->wait_handle = 0; |
| 132 | |||
| 133 | auto lock_owner = thread->lock_owner; | ||
| 134 | // Threads waking up by timeout from WaitProcessWideKey do not perform priority inheritance | ||
| 135 | // and don't have a lock owner. | ||
| 136 | ASSERT(lock_owner == nullptr); | ||
| 132 | } | 137 | } |
| 133 | 138 | ||
| 134 | if (resume) | 139 | if (resume) |
| @@ -325,8 +330,8 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 325 | void Thread::SetPriority(u32 priority) { | 330 | void Thread::SetPriority(u32 priority) { |
| 326 | ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, | 331 | ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, |
| 327 | "Invalid priority value."); | 332 | "Invalid priority value."); |
| 328 | Core::System::GetInstance().Scheduler().SetThreadPriority(this, priority); | 333 | nominal_priority = priority; |
| 329 | nominal_priority = current_priority = priority; | 334 | UpdatePriority(); |
| 330 | } | 335 | } |
| 331 | 336 | ||
| 332 | void Thread::BoostPriority(u32 priority) { | 337 | void Thread::BoostPriority(u32 priority) { |
| @@ -376,6 +381,38 @@ VAddr Thread::GetCommandBufferAddress() const { | |||
| 376 | return GetTLSAddress() + CommandHeaderOffset; | 381 | return GetTLSAddress() + CommandHeaderOffset; |
| 377 | } | 382 | } |
| 378 | 383 | ||
| 384 | void Thread::AddMutexWaiter(SharedPtr<Thread> thread) { | ||
| 385 | thread->lock_owner = this; | ||
| 386 | wait_mutex_threads.emplace_back(std::move(thread)); | ||
| 387 | UpdatePriority(); | ||
| 388 | } | ||
| 389 | |||
| 390 | void Thread::RemoveMutexWaiter(SharedPtr<Thread> thread) { | ||
| 391 | boost::remove_erase(wait_mutex_threads, thread); | ||
| 392 | thread->lock_owner = nullptr; | ||
| 393 | UpdatePriority(); | ||
| 394 | } | ||
| 395 | |||
| 396 | void Thread::UpdatePriority() { | ||
| 397 | // Find the highest priority among all the threads that are waiting for this thread's lock | ||
| 398 | u32 new_priority = nominal_priority; | ||
| 399 | for (const auto& thread : wait_mutex_threads) { | ||
| 400 | if (thread->nominal_priority < new_priority) | ||
| 401 | new_priority = thread->nominal_priority; | ||
| 402 | } | ||
| 403 | |||
| 404 | if (new_priority == current_priority) | ||
| 405 | return; | ||
| 406 | |||
| 407 | Core::System::GetInstance().Scheduler().SetThreadPriority(this, new_priority); | ||
| 408 | |||
| 409 | current_priority = new_priority; | ||
| 410 | |||
| 411 | // Recursively update the priority of the thread that depends on the priority of this one. | ||
| 412 | if (lock_owner) | ||
| 413 | lock_owner->UpdatePriority(); | ||
| 414 | } | ||
| 415 | |||
| 379 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 416 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 380 | 417 | ||
| 381 | /** | 418 | /** |