summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-03-08 12:51:24 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:35:40 -0400
commit6515c6e8c699584528486341579cf3a8dde3eea4 (patch)
tree1663248cbd02cc0db108ed18feef5a994e44d63d /src/core/hle/kernel/svc.cpp
parentScheduler: Correct yields. (diff)
downloadyuzu-6515c6e8c699584528486341579cf3a8dde3eea4.tar.gz
yuzu-6515c6e8c699584528486341579cf3a8dde3eea4.tar.xz
yuzu-6515c6e8c699584528486341579cf3a8dde3eea4.zip
Kernel: Fixes, corrections and asserts to scheduler and different svcs.
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 371beed0d..aad2ac549 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1562,6 +1562,11 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr mutex_add
1562 1562
1563 current_thread->SetSynchronizationResults(nullptr, RESULT_TIMEOUT); 1563 current_thread->SetSynchronizationResults(nullptr, RESULT_TIMEOUT);
1564 1564
1565 if (thread->IsPendingTermination()) {
1566 lock.CancelSleep();
1567 return ERR_THREAD_TERMINATING;
1568 }
1569
1565 const auto release_result = current_process->GetMutex().Release(mutex_addr); 1570 const auto release_result = current_process->GetMutex().Release(mutex_addr);
1566 if (release_result.IsError()) { 1571 if (release_result.IsError()) {
1567 lock.CancelSleep(); 1572 lock.CancelSleep();
@@ -1588,6 +1593,11 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr mutex_add
1588 { 1593 {
1589 SchedulerLock lock(kernel); 1594 SchedulerLock lock(kernel);
1590 1595
1596 auto* owner = current_thread->GetLockOwner();
1597 if (owner != nullptr) {
1598 owner->RemoveMutexWaiter(SharedFrom(current_thread));
1599 }
1600
1591 current_process->RemoveConditionVariableThread(SharedFrom(current_thread)); 1601 current_process->RemoveConditionVariableThread(SharedFrom(current_thread));
1592 } 1602 }
1593 // Note: Deliberately don't attempt to inherit the lock owner's priority. 1603 // Note: Deliberately don't attempt to inherit the lock owner's priority.
@@ -1618,19 +1628,10 @@ static void SignalProcessWideKey(Core::System& system, VAddr condition_variable_
1618 for (std::size_t index = 0; index < last; ++index) { 1628 for (std::size_t index = 0; index < last; ++index) {
1619 auto& thread = waiting_threads[index]; 1629 auto& thread = waiting_threads[index];
1620 1630
1621 if (thread->GetStatus() != ThreadStatus::WaitCondVar) {
1622 last++;
1623 last = std::min(waiting_threads.size(), last);
1624 continue;
1625 }
1626
1627 time_manager.CancelTimeEvent(thread.get());
1628
1629 ASSERT(thread->GetCondVarWaitAddress() == condition_variable_addr); 1631 ASSERT(thread->GetCondVarWaitAddress() == condition_variable_addr);
1630 1632
1631 // liberate Cond Var Thread. 1633 // liberate Cond Var Thread.
1632 current_process->RemoveConditionVariableThread(thread); 1634 current_process->RemoveConditionVariableThread(thread);
1633 thread->SetCondVarWaitAddress(0);
1634 1635
1635 const std::size_t current_core = system.CurrentCoreIndex(); 1636 const std::size_t current_core = system.CurrentCoreIndex();
1636 auto& monitor = system.Monitor(); 1637 auto& monitor = system.Monitor();
@@ -1655,9 +1656,6 @@ static void SignalProcessWideKey(Core::System& system, VAddr condition_variable_
1655 monitor.ClearExclusive(); 1656 monitor.ClearExclusive();
1656 if (mutex_val == 0) { 1657 if (mutex_val == 0) {
1657 // We were able to acquire the mutex, resume this thread. 1658 // We were able to acquire the mutex, resume this thread.
1658 ASSERT(thread->GetStatus() == ThreadStatus::WaitCondVar);
1659 thread->ResumeFromWait();
1660
1661 auto* const lock_owner = thread->GetLockOwner(); 1659 auto* const lock_owner = thread->GetLockOwner();
1662 if (lock_owner != nullptr) { 1660 if (lock_owner != nullptr) {
1663 lock_owner->RemoveMutexWaiter(thread); 1661 lock_owner->RemoveMutexWaiter(thread);
@@ -1665,13 +1663,16 @@ static void SignalProcessWideKey(Core::System& system, VAddr condition_variable_
1665 1663
1666 thread->SetLockOwner(nullptr); 1664 thread->SetLockOwner(nullptr);
1667 thread->SetSynchronizationResults(nullptr, RESULT_SUCCESS); 1665 thread->SetSynchronizationResults(nullptr, RESULT_SUCCESS);
1666 thread->ResumeFromWait();
1668 } else { 1667 } else {
1669 // The mutex is already owned by some other thread, make this thread wait on it. 1668 // The mutex is already owned by some other thread, make this thread wait on it.
1670 const Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); 1669 const Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask);
1671 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1670 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1672 auto owner = handle_table.Get<Thread>(owner_handle); 1671 auto owner = handle_table.Get<Thread>(owner_handle);
1673 ASSERT(owner); 1672 ASSERT(owner);
1674 thread->SetStatus(ThreadStatus::WaitMutex); 1673 if (thread->GetStatus() == ThreadStatus::WaitCondVar) {
1674 thread->SetStatus(ThreadStatus::WaitMutex);
1675 }
1675 1676
1676 owner->AddMutexWaiter(thread); 1677 owner->AddMutexWaiter(thread);
1677 } 1678 }