summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-03-03 13:37:11 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:35:23 -0400
commitb4dc01f16affe4baa9a7ab5ac4b240e03c03ae67 (patch)
tree3bd41c8e286ed564213b9a580e4df875f2687e25 /src
parentCore: Correct HLE Event Callbacks and other issues. (diff)
downloadyuzu-b4dc01f16affe4baa9a7ab5ac4b240e03c03ae67.tar.gz
yuzu-b4dc01f16affe4baa9a7ab5ac4b240e03c03ae67.tar.xz
yuzu-b4dc01f16affe4baa9a7ab5ac4b240e03c03ae67.zip
Kernel: Correct Signal on Thread Death and Setup Sync Objects on Thread for Debugging
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/synchronization.cpp3
-rw-r--r--src/core/hle/kernel/thread.cpp15
-rw-r--r--src/core/hle/kernel/thread.h14
3 files changed, 17 insertions, 15 deletions
diff --git a/src/core/hle/kernel/synchronization.cpp b/src/core/hle/kernel/synchronization.cpp
index 4ee7ad93c..ac43a7094 100644
--- a/src/core/hle/kernel/synchronization.cpp
+++ b/src/core/hle/kernel/synchronization.cpp
@@ -70,6 +70,8 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor(
70 for (auto& object : sync_objects) { 70 for (auto& object : sync_objects) {
71 object->AddWaitingThread(SharedFrom(thread)); 71 object->AddWaitingThread(SharedFrom(thread));
72 } 72 }
73
74 thread->SetSynchronizationObjects(&sync_objects);
73 thread->SetSynchronizationResults(nullptr, RESULT_TIMEOUT); 75 thread->SetSynchronizationResults(nullptr, RESULT_TIMEOUT);
74 thread->SetStatus(ThreadStatus::WaitSynch); 76 thread->SetStatus(ThreadStatus::WaitSynch);
75 } 77 }
@@ -83,6 +85,7 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor(
83 SchedulerLock lock(kernel); 85 SchedulerLock lock(kernel);
84 ResultCode signaling_result = thread->GetSignalingResult(); 86 ResultCode signaling_result = thread->GetSignalingResult();
85 SynchronizationObject* signaling_object = thread->GetSignalingObject(); 87 SynchronizationObject* signaling_object = thread->GetSignalingObject();
88 thread->SetSynchronizationObjects(nullptr);
86 for (auto& obj : sync_objects) { 89 for (auto& obj : sync_objects) {
87 obj->RemoveWaitingThread(SharedFrom(thread)); 90 obj->RemoveWaitingThread(SharedFrom(thread));
88 } 91 }
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 16babe71a..fb1751860 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -50,11 +50,11 @@ void Thread::Stop() {
50 { 50 {
51 SchedulerLock lock(kernel); 51 SchedulerLock lock(kernel);
52 // Cancel any outstanding wakeup events for this thread 52 // Cancel any outstanding wakeup events for this thread
53 Signal();
54 Core::System::GetInstance().CoreTiming().UnscheduleEvent( 53 Core::System::GetInstance().CoreTiming().UnscheduleEvent(
55 kernel.ThreadWakeupCallbackEventType(), global_handle); 54 kernel.ThreadWakeupCallbackEventType(), global_handle);
56 kernel.GlobalHandleTable().Close(global_handle);
57 SetStatus(ThreadStatus::Dead); 55 SetStatus(ThreadStatus::Dead);
56 Signal();
57 kernel.GlobalHandleTable().Close(global_handle);
58 58
59 owner_process->UnregisterThread(this); 59 owner_process->UnregisterThread(this);
60 60
@@ -81,7 +81,6 @@ void Thread::CancelWakeupTimer() {
81} 81}
82 82
83void Thread::ResumeFromWait() { 83void Thread::ResumeFromWait() {
84 ASSERT_MSG(wait_objects.empty(), "Thread is waking up while waiting for objects");
85 SchedulerLock lock(kernel); 84 SchedulerLock lock(kernel);
86 switch (status) { 85 switch (status) {
87 case ThreadStatus::Paused: 86 case ThreadStatus::Paused:
@@ -219,7 +218,7 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy
219 thread->processor_id = processor_id; 218 thread->processor_id = processor_id;
220 thread->ideal_core = processor_id; 219 thread->ideal_core = processor_id;
221 thread->affinity_mask = 1ULL << processor_id; 220 thread->affinity_mask = 1ULL << processor_id;
222 thread->wait_objects.clear(); 221 thread->wait_objects = nullptr;
223 thread->mutex_wait_address = 0; 222 thread->mutex_wait_address = 0;
224 thread->condvar_wait_address = 0; 223 thread->condvar_wait_address = 0;
225 thread->wait_handle = 0; 224 thread->wait_handle = 0;
@@ -272,9 +271,9 @@ void Thread::SetSynchronizationResults(SynchronizationObject* object, ResultCode
272} 271}
273 272
274s32 Thread::GetSynchronizationObjectIndex(std::shared_ptr<SynchronizationObject> object) const { 273s32 Thread::GetSynchronizationObjectIndex(std::shared_ptr<SynchronizationObject> object) const {
275 ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything"); 274 ASSERT_MSG(!wait_objects->empty(), "Thread is not waiting for anything");
276 const auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object); 275 const auto match = std::find(wait_objects->rbegin(), wait_objects->rend(), object);
277 return static_cast<s32>(std::distance(match, wait_objects.rend()) - 1); 276 return static_cast<s32>(std::distance(match, wait_objects->rend()) - 1);
278} 277}
279 278
280VAddr Thread::GetCommandBufferAddress() const { 279VAddr Thread::GetCommandBufferAddress() const {
@@ -389,7 +388,7 @@ void Thread::UpdatePriority() {
389} 388}
390 389
391bool Thread::AllSynchronizationObjectsReady() const { 390bool Thread::AllSynchronizationObjectsReady() const {
392 return std::none_of(wait_objects.begin(), wait_objects.end(), 391 return std::none_of(wait_objects->begin(), wait_objects->end(),
393 [this](const std::shared_ptr<SynchronizationObject>& object) { 392 [this](const std::shared_ptr<SynchronizationObject>& object) {
394 return object->ShouldWait(this); 393 return object->ShouldWait(this);
395 }); 394 });
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index c4c9d69ec..7b6d1b4ec 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -21,7 +21,7 @@ class Fiber;
21 21
22namespace Core { 22namespace Core {
23class System; 23class System;
24} 24} // namespace Core
25 25
26namespace Kernel { 26namespace Kernel {
27 27
@@ -386,18 +386,18 @@ public:
386 } 386 }
387 387
388 const ThreadSynchronizationObjects& GetSynchronizationObjects() const { 388 const ThreadSynchronizationObjects& GetSynchronizationObjects() const {
389 return wait_objects; 389 return *wait_objects;
390 } 390 }
391 391
392 void SetSynchronizationObjects(ThreadSynchronizationObjects objects) { 392 void SetSynchronizationObjects(ThreadSynchronizationObjects* objects) {
393 wait_objects = std::move(objects); 393 wait_objects = objects;
394 } 394 }
395 395
396 void ClearSynchronizationObjects() { 396 void ClearSynchronizationObjects() {
397 for (const auto& waiting_object : wait_objects) { 397 for (const auto& waiting_object : *wait_objects) {
398 waiting_object->RemoveWaitingThread(SharedFrom(this)); 398 waiting_object->RemoveWaitingThread(SharedFrom(this));
399 } 399 }
400 wait_objects.clear(); 400 wait_objects->clear();
401 } 401 }
402 402
403 /// Determines whether all the objects this thread is waiting on are ready. 403 /// Determines whether all the objects this thread is waiting on are ready.
@@ -595,7 +595,7 @@ private:
595 595
596 /// Objects that the thread is waiting on, in the same order as they were 596 /// Objects that the thread is waiting on, in the same order as they were
597 /// passed to WaitSynchronization. 597 /// passed to WaitSynchronization.
598 ThreadSynchronizationObjects wait_objects; 598 ThreadSynchronizationObjects* wait_objects;
599 599
600 SynchronizationObject* signaling_object; 600 SynchronizationObject* signaling_object;
601 ResultCode signaling_result{RESULT_SUCCESS}; 601 ResultCode signaling_result{RESULT_SUCCESS};