mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 23:00:10 +00:00
Thread: Convert some uses of handles to pointers
This commit is contained in:
parent
333557152c
commit
4637df2721
@ -13,7 +13,7 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
Handle g_main_thread = 0;
|
||||
Thread* g_main_thread = nullptr;
|
||||
HandleTable g_handle_table;
|
||||
u64 g_program_id = 0;
|
||||
|
||||
|
@ -16,6 +16,8 @@ const Handle INVALID_HANDLE = 0;
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Thread;
|
||||
|
||||
// TODO: Verify code
|
||||
const ResultCode ERR_OUT_OF_HANDLES(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
|
||||
ErrorSummary::OutOfResource, ErrorLevel::Temporary);
|
||||
@ -189,7 +191,7 @@ private:
|
||||
};
|
||||
|
||||
extern HandleTable g_handle_table;
|
||||
extern Handle g_main_thread;
|
||||
extern Thread* g_main_thread;
|
||||
|
||||
/// The ID code of the currently running game
|
||||
/// TODO(Subv): This variable should not be here,
|
||||
|
@ -290,7 +290,7 @@ void DebugThreadQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
ResultVal<Handle> Thread::Create(const char* name, u32 entry_point, s32 priority, u32 arg,
|
||||
ResultVal<Thread*> Thread::Create(const char* name, u32 entry_point, s32 priority, u32 arg,
|
||||
s32 processor_id, u32 stack_top, int stack_size) {
|
||||
_dbg_assert_(Kernel, name != nullptr);
|
||||
|
||||
@ -319,6 +319,7 @@ ResultVal<Handle> Thread::Create(const char* name, u32 entry_point, s32 priority
|
||||
|
||||
Thread* thread = new Thread;
|
||||
|
||||
// TODO(yuriks): Thread requires a handle to be inserted into the various scheduling queues for now.
|
||||
ResultVal<Handle> handle = Kernel::g_handle_table.Create(thread);
|
||||
// TODO(yuriks): Plug memory leak
|
||||
if (handle.Failed())
|
||||
@ -342,7 +343,7 @@ ResultVal<Handle> Thread::Create(const char* name, u32 entry_point, s32 priority
|
||||
ResetThread(thread, arg, 0);
|
||||
CallThread(thread);
|
||||
|
||||
return MakeResult<Handle>(*handle);
|
||||
return MakeResult<Thread*>(thread);
|
||||
}
|
||||
|
||||
/// Set the priority of the thread specified by handle
|
||||
@ -372,14 +373,13 @@ void Thread::SetPriority(s32 priority) {
|
||||
}
|
||||
|
||||
/// Sets up the primary application thread
|
||||
Handle SetupMainThread(s32 priority, int stack_size) {
|
||||
Thread* SetupMainThread(s32 priority, int stack_size) {
|
||||
// Initialize new "main" thread
|
||||
ResultVal<Handle> handle = Thread::Create("main", Core::g_app_core->GetPC(), priority, 0,
|
||||
ResultVal<Thread*> thread_res = Thread::Create("main", Core::g_app_core->GetPC(), priority, 0,
|
||||
THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size);
|
||||
// TODO(yuriks): Propagate error
|
||||
_dbg_assert_(Kernel, handle.Succeeded());
|
||||
|
||||
Thread* thread = Kernel::g_handle_table.Get<Thread>(*handle);
|
||||
_dbg_assert_(Kernel, thread_res.Succeeded());
|
||||
Thread* thread = *thread_res;
|
||||
|
||||
// If running another thread already, set it to "ready" state
|
||||
Thread* cur = GetCurrentThread();
|
||||
@ -392,7 +392,7 @@ Handle SetupMainThread(s32 priority, int stack_size) {
|
||||
thread->status = THREADSTATUS_RUNNING;
|
||||
LoadContext(thread->context);
|
||||
|
||||
return *handle;
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace Kernel {
|
||||
|
||||
class Thread : public Kernel::Object {
|
||||
public:
|
||||
static ResultVal<Handle> Create(const char* name, u32 entry_point, s32 priority, u32 arg,
|
||||
static ResultVal<Thread*> Create(const char* name, u32 entry_point, s32 priority, u32 arg,
|
||||
s32 processor_id, u32 stack_top, int stack_size = Kernel::DEFAULT_STACK_SIZE);
|
||||
|
||||
std::string GetName() const override { return name; }
|
||||
@ -102,7 +102,7 @@ private:
|
||||
};
|
||||
|
||||
/// Sets up the primary application thread
|
||||
Handle SetupMainThread(s32 priority, int stack_size=Kernel::DEFAULT_STACK_SIZE);
|
||||
Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZE);
|
||||
|
||||
/// Reschedules to the next available thread (call after current thread is suspended)
|
||||
void Reschedule();
|
||||
|
@ -229,16 +229,17 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
|
||||
name = Common::StringFromFormat("unknown-%08x", entry_point);
|
||||
}
|
||||
|
||||
ResultVal<Handle> thread = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg,
|
||||
ResultVal<Kernel::Thread*> thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg,
|
||||
processor_id, stack_top);
|
||||
if (thread.Failed())
|
||||
return thread.Code().raw;
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user