mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-26 18:15:43 +01:00
core: hle: kernel: k_thread: Add KScopedDisableDispatch.
This commit is contained in:
parent
2b9560428b
commit
01af2f4162
@ -188,7 +188,7 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s
|
|||||||
// Setup the stack parameters.
|
// Setup the stack parameters.
|
||||||
StackParameters& sp = GetStackParameters();
|
StackParameters& sp = GetStackParameters();
|
||||||
sp.cur_thread = this;
|
sp.cur_thread = this;
|
||||||
sp.disable_count = 1;
|
sp.disable_count = 0;
|
||||||
SetInExceptionHandler();
|
SetInExceptionHandler();
|
||||||
|
|
||||||
// Set thread ID.
|
// Set thread ID.
|
||||||
@ -970,6 +970,9 @@ ResultCode KThread::Run() {
|
|||||||
|
|
||||||
// Set our state and finish.
|
// Set our state and finish.
|
||||||
SetState(ThreadState::Runnable);
|
SetState(ThreadState::Runnable);
|
||||||
|
|
||||||
|
DisableDispatch();
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1054,4 +1057,16 @@ s32 GetCurrentCoreId(KernelCore& kernel) {
|
|||||||
return GetCurrentThread(kernel).GetCurrentCore();
|
return GetCurrentThread(kernel).GetCurrentCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KScopedDisableDispatch::~KScopedDisableDispatch() {
|
||||||
|
if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) {
|
||||||
|
auto scheduler = kernel.CurrentScheduler();
|
||||||
|
|
||||||
|
if (scheduler) {
|
||||||
|
scheduler->RescheduleCurrentCore();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GetCurrentThread(kernel).EnableDispatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -450,16 +450,35 @@ public:
|
|||||||
sleeping_queue = q;
|
sleeping_queue = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool IsKernelThread() const {
|
||||||
|
return GetActiveCore() == 3;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] s32 GetDisableDispatchCount() const {
|
[[nodiscard]] s32 GetDisableDispatchCount() const {
|
||||||
|
if (IsKernelThread()) {
|
||||||
|
// TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return this->GetStackParameters().disable_count;
|
return this->GetStackParameters().disable_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisableDispatch() {
|
void DisableDispatch() {
|
||||||
|
if (IsKernelThread()) {
|
||||||
|
// TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
||||||
this->GetStackParameters().disable_count++;
|
this->GetStackParameters().disable_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableDispatch() {
|
void EnableDispatch() {
|
||||||
|
if (IsKernelThread()) {
|
||||||
|
// TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0);
|
||||||
this->GetStackParameters().disable_count--;
|
this->GetStackParameters().disable_count--;
|
||||||
}
|
}
|
||||||
@ -752,4 +771,16 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class KScopedDisableDispatch {
|
||||||
|
public:
|
||||||
|
explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} {
|
||||||
|
GetCurrentThread(kernel).DisableDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
~KScopedDisableDispatch();
|
||||||
|
|
||||||
|
private:
|
||||||
|
KernelCore& kernel;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
Loading…
Reference in New Issue
Block a user