kernel: refactor dummy thread wakeups
This commit is contained in:
parent
99cefb62fd
commit
3980952ab8
5 changed files with 79 additions and 29 deletions
|
@ -148,7 +148,9 @@ Result KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack
|
|||
physical_affinity_mask.SetAffinity(phys_core, true);
|
||||
|
||||
// Set the thread state.
|
||||
thread_state = (type == ThreadType::Main) ? ThreadState::Runnable : ThreadState::Initialized;
|
||||
thread_state = (type == ThreadType::Main || type == ThreadType::Dummy)
|
||||
? ThreadState::Runnable
|
||||
: ThreadState::Initialized;
|
||||
|
||||
// Set TLS address.
|
||||
tls_address = 0;
|
||||
|
@ -1174,30 +1176,29 @@ Result KThread::Sleep(s64 timeout) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KThread::IfDummyThreadTryWait() {
|
||||
if (!IsDummyThread()) {
|
||||
return;
|
||||
}
|
||||
void KThread::RequestDummyThreadWait() {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||
ASSERT(this->IsDummyThread());
|
||||
|
||||
if (GetState() != ThreadState::Waiting) {
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT(!kernel.IsPhantomModeForSingleCore());
|
||||
|
||||
// Block until we are no longer waiting.
|
||||
std::unique_lock lk(dummy_wait_lock);
|
||||
dummy_wait_cv.wait(
|
||||
lk, [&] { return GetState() != ThreadState::Waiting || kernel.IsShuttingDown(); });
|
||||
// We will block when the scheduler lock is released.
|
||||
dummy_thread_runnable.store(false);
|
||||
}
|
||||
|
||||
void KThread::IfDummyThreadEndWait() {
|
||||
if (!IsDummyThread()) {
|
||||
return;
|
||||
}
|
||||
void KThread::DummyThreadBeginWait() {
|
||||
ASSERT(this->IsDummyThread());
|
||||
ASSERT(!kernel.IsPhantomModeForSingleCore());
|
||||
|
||||
// Block until runnable is no longer false.
|
||||
dummy_thread_runnable.wait(false);
|
||||
}
|
||||
|
||||
void KThread::DummyThreadEndWait() {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||
ASSERT(this->IsDummyThread());
|
||||
|
||||
// Wake up the waiting thread.
|
||||
dummy_wait_cv.notify_one();
|
||||
dummy_thread_runnable.store(true);
|
||||
dummy_thread_runnable.notify_one();
|
||||
}
|
||||
|
||||
void KThread::BeginWait(KThreadQueue* queue) {
|
||||
|
@ -1231,9 +1232,6 @@ void KThread::EndWait(Result wait_result_) {
|
|||
}
|
||||
|
||||
wait_queue->EndWait(this, wait_result_);
|
||||
|
||||
// Special case for dummy threads to wakeup if necessary.
|
||||
IfDummyThreadEndWait();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue