aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2017-09-28 11:53:32 -0500
committerSubv <subv2112@gmail.com>2017-09-28 11:53:32 -0500
commit8432749db7afecc9beea20f993cc036418caaa15 (patch)
tree10dd3fcd755bd7bdc27eef120885c7e700ab4288 /src/core/hle/kernel/thread.cpp
parent0d42706a7b50f0d2444d56932297480e4a4a3ae6 (diff)
Kernel/Threads: When putting a thread to wait, specify a function to execute when it is awoken.
This change makes for a clearer (less confusing) path of execution in the scheduler, now the code to execute when a thread awakes is closer to the code that puts the thread to sleep (WaitSynch1, WaitSynchN). It also allows us to implement the special wake up behavior of ReplyAndReceive without hacking up WaitObject::WakeupAllWaitingThreads. If savestates are desired in the future, we can change this implementation to one similar to the CoreTiming event system, where we first register the callback functions at startup and assign their identifiers to the Thread callback variable instead of directly assigning a lambda to the wake up callback variable.
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 61378211f..690cb20b3 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -247,12 +247,15 @@ static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) {
if (thread->status == THREADSTATUS_WAIT_SYNCH_ANY ||
thread->status == THREADSTATUS_WAIT_SYNCH_ALL || thread->status == THREADSTATUS_WAIT_ARB) {
- thread->wait_set_output = false;
+
+ // Invoke the wakeup callback before clearing the wait objects
+ if (thread->wakeup_callback)
+ thread->wakeup_callback(ThreadWakeupReason::Timeout, thread, nullptr);
+
// Remove the thread from each of its waiting objects' waitlists
for (auto& object : thread->wait_objects)
object->RemoveWaitingThread(thread.get());
thread->wait_objects.clear();
- thread->SetWaitSynchronizationResult(RESULT_TIMEOUT);
}
thread->ResumeFromWait();
@@ -278,6 +281,9 @@ void Thread::ResumeFromWait() {
break;
case THREADSTATUS_READY:
+ // The thread's wakeup callback must have already been cleared when the thread was first
+ // awoken.
+ ASSERT(wakeup_callback == nullptr);
// If the thread is waiting on multiple wait objects, it might be awoken more than once
// before actually resuming. We can ignore subsequent wakeups if the thread status has
// already been set to THREADSTATUS_READY.
@@ -293,6 +299,8 @@ void Thread::ResumeFromWait() {
return;
}
+ wakeup_callback = nullptr;
+
ready_queue.push_back(current_priority, this);
status = THREADSTATUS_READY;
Core::System::GetInstance().PrepareReschedule();
@@ -394,7 +402,6 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
thread->nominal_priority = thread->current_priority = priority;
thread->last_running_ticks = CoreTiming::GetTicks();
thread->processor_id = processor_id;
- thread->wait_set_output = false;
thread->wait_objects.clear();
thread->wait_address = 0;
thread->name = std::move(name);