Thread: Modernize two functions that slipped through previous rebases

This commit is contained in:
Yuri Kunde Schlesner 2015-01-30 23:07:54 -02:00
parent 6e11570862
commit 664c79ff47
4 changed files with 16 additions and 18 deletions

View File

@ -51,7 +51,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address,
case ArbitrationType::WaitIfLessThanWithTimeout:
if ((s32)Memory::Read32(address) <= value) {
Kernel::WaitCurrentThread_ArbitrateAddress(address);
Kernel::WakeThreadAfterDelay(GetCurrentThread(), nanoseconds);
GetCurrentThread()->WakeAfterDelay(nanoseconds);
HLE::Reschedule(__func__);
}
break;
@ -71,7 +71,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address,
Memory::Write32(address, memory_value);
if (memory_value <= value) {
Kernel::WaitCurrentThread_ArbitrateAddress(address);
Kernel::WakeThreadAfterDelay(GetCurrentThread(), nanoseconds);
GetCurrentThread()->WakeAfterDelay(nanoseconds);
HLE::Reschedule(__func__);
}
break;

View File

@ -248,14 +248,13 @@ static void ThreadWakeupCallback(u64 parameter, int cycles_late) {
}
void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds) {
void Thread::WakeAfterDelay(s64 nanoseconds) {
// Don't schedule a wakeup if the thread wants to wait forever
if (nanoseconds == -1)
return;
_dbg_assert_(Kernel, thread != nullptr);
u64 microseconds = nanoseconds / 1000;
CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, thread->GetHandle());
CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, GetHandle());
}
void Thread::ReleaseWaitObject(WaitObject* wait_object) {
@ -418,7 +417,7 @@ void Thread::SetPriority(s32 priority) {
}
}
Handle SetupIdleThread() {
SharedPtr<Thread> SetupIdleThread() {
// We need to pass a few valid values to get around parameter checking in Thread::Create.
auto thread_res = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0,
THREADPROCESSORID_0, 0, Kernel::DEFAULT_STACK_SIZE);
@ -427,7 +426,7 @@ Handle SetupIdleThread() {
thread->idle = true;
CallThread(thread.get());
return thread->GetHandle();
return thread;
}
SharedPtr<Thread> SetupMainThread(s32 priority, u32 stack_size) {

View File

@ -77,6 +77,12 @@ public:
/// Resumes a thread from waiting by marking it as "ready"
void ResumeFromWait();
/**
* 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.
*/
void WakeAfterDelay(s64 nanoseconds);
/**
* Sets the result after the thread awakens (from either WaitSynchronization SVC)
* @param result Value to set to the returned result
@ -150,20 +156,13 @@ void WaitCurrentThread_WaitSynchronization(SharedPtr<WaitObject> wait_object, bo
*/
void WaitCurrentThread_ArbitrateAddress(VAddr wait_address);
/**
* Schedules an event to wake up the specified thread after the specified delay.
* @param handle The thread handle.
* @param nanoseconds The time this thread will be allowed to sleep for.
*/
void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds);
/**
* Sets up the idle thread, this is a thread that is intended to never execute instructions,
* only to advance the timing. It is scheduled when there are no other ready threads in the thread queue
* and will try to yield on every call.
* @returns The handle of the idle thread
*/
Handle SetupIdleThread();
SharedPtr<Thread> SetupIdleThread();
/// Initialize threading
void ThreadingInit();

View File

@ -152,7 +152,7 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) {
Kernel::WaitCurrentThread_WaitSynchronization(object, false, false);
// Create an event to wake the thread up after the specified nanosecond delay has passed
Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nano_seconds);
Kernel::GetCurrentThread()->WakeAfterDelay(nano_seconds);
HLE::Reschedule(__func__);
@ -228,7 +228,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou
}
// Create an event to wake the thread up after the specified nanosecond delay has passed
Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nano_seconds);
Kernel::GetCurrentThread()->WakeAfterDelay(nano_seconds);
HLE::Reschedule(__func__);
@ -540,7 +540,7 @@ static void SleepThread(s64 nanoseconds) {
Kernel::WaitCurrentThread_Sleep();
// Create an event to wake the thread up after the specified nanosecond delay has passed
Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds);
Kernel::GetCurrentThread()->WakeAfterDelay(nanoseconds);
HLE::Reschedule(__func__);
}