kernel/svc: Migrate svcCancelSynchronization behavior to a thread function
The actual behavior of this function is slightly more complex than what we're currently doing within the supervisor call. To avoid dumping most of this behavior in the supervisor call itself, we can migrate this to another function.
This commit is contained in:
parent
0cfbd3325b
commit
433b59c112
3 changed files with 17 additions and 7 deletions
|
@ -518,16 +518,14 @@ static ResultCode CancelSynchronization(Core::System& system, Handle thread_hand
|
||||||
LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle);
|
LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle);
|
||||||
|
|
||||||
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
|
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
|
||||||
const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
|
SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
|
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
|
||||||
thread_handle);
|
thread_handle);
|
||||||
return ERR_INVALID_HANDLE;
|
return ERR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(thread->GetStatus() == ThreadStatus::WaitSynchAny);
|
thread->CancelWait();
|
||||||
thread->SetWaitSynchronizationResult(ERR_SYNCHRONIZATION_CANCELED);
|
|
||||||
thread->ResumeFromWait();
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,12 @@ void Thread::ResumeFromWait() {
|
||||||
ChangeScheduler();
|
ChangeScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Thread::CancelWait() {
|
||||||
|
ASSERT(GetStatus() == ThreadStatus::WaitSynchAny);
|
||||||
|
SetWaitSynchronizationResult(ERR_SYNCHRONIZATION_CANCELED);
|
||||||
|
ResumeFromWait();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets a thread context, making it ready to be scheduled and run by the CPU
|
* Resets a thread context, making it ready to be scheduled and run by the CPU
|
||||||
* @param context Thread context to reset
|
* @param context Thread context to reset
|
||||||
|
|
|
@ -164,11 +164,17 @@ public:
|
||||||
return tls_memory;
|
return tls_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Resumes a thread from waiting
|
||||||
* Resumes a thread from waiting
|
|
||||||
*/
|
|
||||||
void ResumeFromWait();
|
void ResumeFromWait();
|
||||||
|
|
||||||
|
/// Cancels a waiting operation that this thread may or may not be within.
|
||||||
|
///
|
||||||
|
/// When the thread is within a waiting state, this will set the thread's
|
||||||
|
/// waiting result to signal a canceled wait. The function will then resume
|
||||||
|
/// this thread.
|
||||||
|
///
|
||||||
|
void CancelWait();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules an event to wake up the specified thread after the specified delay
|
* Schedules an event to wake up the specified thread after the specified delay
|
||||||
* @param nanoseconds The time this thread will be allowed to sleep for
|
* @param nanoseconds The time this thread will be allowed to sleep for
|
||||||
|
|
Loading…
Reference in a new issue