summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-03-19 20:57:31 -0400
committerGravatar FernandoS272019-03-19 22:43:13 -0400
commit9c7319a4d423a20c45cd8d7898c2f73659526d33 (patch)
tree04113e5a14cd55e88b2866c9d2f33e6fb59858dd /src
parentAdd CondVar Thread State. (diff)
downloadyuzu-9c7319a4d423a20c45cd8d7898c2f73659526d33.tar.gz
yuzu-9c7319a4d423a20c45cd8d7898c2f73659526d33.tar.xz
yuzu-9c7319a4d423a20c45cd8d7898c2f73659526d33.zip
Fix small bug that kept a thread as a condvar thread after being signalled.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/kernel.cpp3
-rw-r--r--src/core/hle/kernel/svc.cpp11
2 files changed, 8 insertions, 6 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 6a7793a3a..8de62d073 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -62,7 +62,8 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] int cycles_
62 62
63 if (thread->GetMutexWaitAddress() != 0 || thread->GetCondVarWaitAddress() != 0 || 63 if (thread->GetMutexWaitAddress() != 0 || thread->GetCondVarWaitAddress() != 0 ||
64 thread->GetWaitHandle() != 0) { 64 thread->GetWaitHandle() != 0) {
65 ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex || thread->GetStatus() == ThreadStatus::WaitCondVar); 65 ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex ||
66 thread->GetStatus() == ThreadStatus::WaitCondVar);
66 thread->SetMutexWaitAddress(0); 67 thread->SetMutexWaitAddress(0);
67 thread->SetCondVarWaitAddress(0); 68 thread->SetCondVarWaitAddress(0);
68 thread->SetWaitHandle(0); 69 thread->SetWaitHandle(0);
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 37608e27a..d40a2226b 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1405,6 +1405,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
1405 1405
1406 ASSERT(thread->GetCondVarWaitAddress() == condition_variable_addr); 1406 ASSERT(thread->GetCondVarWaitAddress() == condition_variable_addr);
1407 1407
1408 // liberate Cond Var Thread.
1409 thread->SetCondVarWaitAddress(0);
1410
1408 std::size_t current_core = Core::System::GetInstance().CurrentCoreIndex(); 1411 std::size_t current_core = Core::System::GetInstance().CurrentCoreIndex();
1409 1412
1410 auto& monitor = Core::System::GetInstance().Monitor(); 1413 auto& monitor = Core::System::GetInstance().Monitor();
@@ -1423,10 +1426,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
1423 } 1426 }
1424 } while (!monitor.ExclusiveWrite32(current_core, thread->GetMutexWaitAddress(), 1427 } while (!monitor.ExclusiveWrite32(current_core, thread->GetMutexWaitAddress(),
1425 thread->GetWaitHandle())); 1428 thread->GetWaitHandle()));
1426
1427 if (mutex_val == 0) { 1429 if (mutex_val == 0) {
1428 // We were able to acquire the mutex, resume this thread. 1430 // We were able to acquire the mutex, resume this thread.
1429 ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); 1431 ASSERT(thread->GetStatus() == ThreadStatus::WaitCondVar);
1430 thread->ResumeFromWait(); 1432 thread->ResumeFromWait();
1431 1433
1432 auto* const lock_owner = thread->GetLockOwner(); 1434 auto* const lock_owner = thread->GetLockOwner();
@@ -1436,8 +1438,8 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
1436 1438
1437 thread->SetLockOwner(nullptr); 1439 thread->SetLockOwner(nullptr);
1438 thread->SetMutexWaitAddress(0); 1440 thread->SetMutexWaitAddress(0);
1439 thread->SetCondVarWaitAddress(0);
1440 thread->SetWaitHandle(0); 1441 thread->SetWaitHandle(0);
1442 Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();
1441 } else { 1443 } else {
1442 // Atomically signal that the mutex now has a waiting thread. 1444 // Atomically signal that the mutex now has a waiting thread.
1443 do { 1445 do {
@@ -1458,10 +1460,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
1458 ASSERT(owner); 1460 ASSERT(owner);
1459 ASSERT(thread->GetStatus() == ThreadStatus::WaitCondVar); 1461 ASSERT(thread->GetStatus() == ThreadStatus::WaitCondVar);
1460 thread->InvalidateWakeupCallback(); 1462 thread->InvalidateWakeupCallback();
1463 thread->SetStatus(ThreadStatus::WaitMutex);
1461 1464
1462 owner->AddMutexWaiter(thread); 1465 owner->AddMutexWaiter(thread);
1463
1464 Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();
1465 } 1466 }
1466 } 1467 }
1467 1468