From 7b3452c7303cf348377de6702ddda0307533663c Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 22 Dec 2014 04:30:09 -0200 Subject: Move ThreadContext to core/core.h and deal with the fallout --- src/core/hle/svc.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index cdcdea36d..92de442e8 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -7,6 +7,7 @@ #include "common/string_util.h" #include "common/symbols.h" +#include "core/arm/arm_interface.h" #include "core/mem_map.h" #include "core/hle/kernel/address_arbiter.h" -- cgit v1.2.3 From 9bf8462b96d34b30f62b8aca745dd558e7f0a450 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 22 Dec 2014 11:07:22 -0200 Subject: Thread: Reduce use of Handles and move some funcs to inside the class. --- src/core/hle/svc.cpp | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 92de442e8..6380d214c 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -231,41 +231,47 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top name = Common::StringFromFormat("unknown-%08x", entry_point); } - Handle thread = Kernel::CreateThread(name.c_str(), entry_point, priority, arg, processor_id, - stack_top); + ResultVal thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg, + processor_id, stack_top); + if (thread_res.Failed()) + return thread_res.Code().raw; + Kernel::Thread* thread = *thread_res; - Core::g_app_core->SetReg(1, thread); + Core::g_app_core->SetReg(1, thread->GetHandle()); LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, - name.c_str(), arg, stack_top, priority, processor_id, thread); + name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle()); return 0; } /// Called when a thread exits -static u32 ExitThread() { - Handle thread = Kernel::GetCurrentThreadHandle(); +static void ExitThread() { + LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); - LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C - - Kernel::StopThread(thread, __func__); + Kernel::GetCurrentThread()->Stop(__func__); HLE::Reschedule(__func__); - return 0; } /// Gets the priority for the specified thread static Result GetThreadPriority(s32* priority, Handle handle) { - ResultVal priority_result = Kernel::GetThreadPriority(handle); - if (priority_result.Succeeded()) { - *priority = *priority_result; - } - return priority_result.Code().raw; + const Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *priority = thread->GetPriority(); + return RESULT_SUCCESS.raw; } /// Sets the priority for the specified thread static Result SetThreadPriority(Handle handle, s32 priority) { - return Kernel::SetThreadPriority(handle, priority).raw; + Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + thread->SetPriority(priority); + return RESULT_SUCCESS.raw; } /// Create a mutex @@ -286,8 +292,13 @@ static Result ReleaseMutex(Handle handle) { /// Get the ID for the specified thread. static Result GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); - ResultCode result = Kernel::GetThreadId(thread_id, handle); - return result.raw; + + const Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *thread_id = thread->GetThreadId(); + return RESULT_SUCCESS.raw; } /// Creates a semaphore @@ -375,7 +386,7 @@ static void SleepThread(s64 nanoseconds) { Kernel::WaitCurrentThread(WAITTYPE_SLEEP); // Create an event to wake the thread up after the specified nanosecond delay has passed - Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThreadHandle(), nanoseconds); + Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds); HLE::Reschedule(__func__); } @@ -407,7 +418,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x06, nullptr, "GetProcessIdealProcessor"}, {0x07, nullptr, "SetProcessIdealProcessor"}, {0x08, HLE::Wrap, "CreateThread"}, - {0x09, HLE::Wrap, "ExitThread"}, + {0x09, ExitThread, "ExitThread"}, {0x0A, HLE::Wrap, "SleepThread"}, {0x0B, HLE::Wrap, "GetThreadPriority"}, {0x0C, HLE::Wrap, "SetThreadPriority"}, -- cgit v1.2.3