|
|
@ -56,12 +56,6 @@ void Thread::Stop() {
|
|
|
|
SetStatus(ThreadStatus::Dead);
|
|
|
|
SetStatus(ThreadStatus::Dead);
|
|
|
|
Signal();
|
|
|
|
Signal();
|
|
|
|
|
|
|
|
|
|
|
|
// Clean up any dangling references in objects that this thread was waiting for
|
|
|
|
|
|
|
|
for (auto& wait_object : wait_objects) {
|
|
|
|
|
|
|
|
wait_object->RemoveWaitingThread(SharedFrom(this));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_objects.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
owner_process->UnregisterThread(this);
|
|
|
|
owner_process->UnregisterThread(this);
|
|
|
|
|
|
|
|
|
|
|
|
// Mark the TLS slot in the thread's page as free.
|
|
|
|
// Mark the TLS slot in the thread's page as free.
|
|
|
@ -138,6 +132,12 @@ void Thread::OnWakeUp() {
|
|
|
|
SetStatus(ThreadStatus::Ready);
|
|
|
|
SetStatus(ThreadStatus::Ready);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultCode Thread::Start() {
|
|
|
|
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
|
|
|
|
SetStatus(ThreadStatus::Ready);
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::CancelWait() {
|
|
|
|
void Thread::CancelWait() {
|
|
|
|
if (GetSchedulingStatus() != ThreadSchedStatus::Paused) {
|
|
|
|
if (GetSchedulingStatus() != ThreadSchedStatus::Paused) {
|
|
|
|
is_sync_cancelled = true;
|
|
|
|
is_sync_cancelled = true;
|
|
|
@ -188,7 +188,7 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy
|
|
|
|
void* thread_start_parameter) {
|
|
|
|
void* thread_start_parameter) {
|
|
|
|
auto& kernel = system.Kernel();
|
|
|
|
auto& kernel = system.Kernel();
|
|
|
|
// Check if priority is in ranged. Lowest priority -> highest priority id.
|
|
|
|
// Check if priority is in ranged. Lowest priority -> highest priority id.
|
|
|
|
if (priority > THREADPRIO_LOWEST && (type_flags & THREADTYPE_IDLE == 0)) {
|
|
|
|
if (priority > THREADPRIO_LOWEST && ((type_flags & THREADTYPE_IDLE) == 0)) {
|
|
|
|
LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority);
|
|
|
|
LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority);
|
|
|
|
return ERR_INVALID_THREAD_PRIORITY;
|
|
|
|
return ERR_INVALID_THREAD_PRIORITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -416,7 +416,7 @@ void Thread::SetActivity(ThreadActivity value) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::Sleep(s64 nanoseconds) {
|
|
|
|
ResultCode Thread::Sleep(s64 nanoseconds) {
|
|
|
|
Handle event_handle{};
|
|
|
|
Handle event_handle{};
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SchedulerLockAndSleep lock(kernel, event_handle, this, nanoseconds);
|
|
|
|
SchedulerLockAndSleep lock(kernel, event_handle, this, nanoseconds);
|
|
|
@ -427,33 +427,31 @@ void Thread::Sleep(s64 nanoseconds) {
|
|
|
|
auto& time_manager = kernel.TimeManager();
|
|
|
|
auto& time_manager = kernel.TimeManager();
|
|
|
|
time_manager.UnscheduleTimeEvent(event_handle);
|
|
|
|
time_manager.UnscheduleTimeEvent(event_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Thread::YieldSimple() {
|
|
|
|
ResultCode Thread::YieldSimple() {
|
|
|
|
bool result{};
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
result = kernel.GlobalScheduler().YieldThread(this);
|
|
|
|
kernel.GlobalScheduler().YieldThread(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Thread::YieldAndBalanceLoad() {
|
|
|
|
ResultCode Thread::YieldAndBalanceLoad() {
|
|
|
|
bool result{};
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
result = kernel.GlobalScheduler().YieldThreadAndBalanceLoad(this);
|
|
|
|
kernel.GlobalScheduler().YieldThreadAndBalanceLoad(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Thread::YieldAndWaitForLoadBalancing() {
|
|
|
|
ResultCode Thread::YieldAndWaitForLoadBalancing() {
|
|
|
|
bool result{};
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
SchedulerLock lock(kernel);
|
|
|
|
result = kernel.GlobalScheduler().YieldThreadAndWaitForLoadBalancing(this);
|
|
|
|
kernel.GlobalScheduler().YieldThreadAndWaitForLoadBalancing(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::SetSchedulingStatus(ThreadSchedStatus new_status) {
|
|
|
|
void Thread::SetSchedulingStatus(ThreadSchedStatus new_status) {
|
|
|
|