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/kernel/thread.h | 68 ++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 46 deletions(-) (limited to 'src/core/hle/kernel/thread.h') diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 51290975e..24450379c 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -54,6 +54,9 @@ namespace Kernel { class Thread : public Kernel::Object { public: + static ResultVal 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; } std::string GetTypeName() const override { return "Thread"; } @@ -69,6 +72,15 @@ public: ResultVal WaitSynchronization() override; + s32 GetPriority() const { return current_priority; } + void SetPriority(s32 priority); + + u32 GetThreadId() const { return thread_id; } + + void Stop(const char* reason); + /// Resumes a thread from waiting by marking it as "ready". + void ResumeFromWait(); + Core::ThreadContext context; u32 thread_id; @@ -84,10 +96,10 @@ public: s32 processor_id; WaitType wait_type; - Handle wait_handle; + Object* wait_object; VAddr wait_address; - std::vector waiting_threads; + std::vector waiting_threads; // TODO(yuriks): Owned std::string name; @@ -95,79 +107,47 @@ public: bool idle = false; private: - // TODO(yuriks) Temporary until the creation logic can be moved into a static function - friend Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 priority, - s32 processor_id, u32 stack_top, int stack_size); - Thread() = default; }; -/// Creates a new thread - wrapper for external user -Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id, - u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE); - /// 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(); -/// Stops the current thread -ResultCode StopThread(Handle thread, const char* reason); - -/** - * Retrieves the ID of the specified thread handle - * @param thread_id Will contain the output thread id - * @param handle Handle to the thread we want - * @return Whether the function was successful or not - */ -ResultCode GetThreadId(u32* thread_id, Handle handle); - -/// Resumes a thread from waiting by marking it as "ready" -void ResumeThreadFromWait(Handle handle); - /// Arbitrate the highest priority thread that is waiting -Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address); +Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address); /// Arbitrate all threads currently waiting... -void ArbitrateAllThreads(u32 arbiter, u32 address); +void ArbitrateAllThreads(Object* arbiter, u32 address); /// Gets the current thread Thread* GetCurrentThread(); -/// Gets the current thread handle -Handle GetCurrentThreadHandle(); - /** * Puts the current thread in the wait state for the given type * @param wait_type Type of wait - * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread + * @param wait_object Kernel object that we are waiting on, defaults to current thread */ -void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); +void WaitCurrentThread(WaitType wait_type, Object* wait_object = GetCurrentThread()); /** * 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(Handle handle, s64 nanoseconds); +void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds); /** * Puts the current thread in the wait state for the given type * @param wait_type Type of wait - * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread + * @param wait_object Kernel object that we are waiting on * @param wait_address Arbitration address used to resume from wait */ -void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address); +void WaitCurrentThread(WaitType wait_type, Object* wait_object, VAddr wait_address); -/// Put current thread in a wait state - on WaitSynchronization -void WaitThread_Synchronization(); -/// Get the priority of the thread specified by handle -ResultVal GetThreadPriority(const Handle handle); - -/// Set the priority of the thread specified by handle -ResultCode SetThreadPriority(Handle handle, s32 priority); /** * Sets up the idle thread, this is a thread that is intended to never execute instructions, @@ -176,10 +156,6 @@ ResultCode SetThreadPriority(Handle handle, s32 priority); * @returns The handle of the idle thread */ Handle SetupIdleThread(); - -/// Whether the current thread is an idle thread -bool IsIdleThread(Handle thread); - /// Initialize threading void ThreadingInit(); -- cgit v1.2.3