diff options
Diffstat (limited to 'src/core/hle/kernel/thread.h')
| -rw-r--r-- | src/core/hle/kernel/thread.h | 109 |
1 files changed, 71 insertions, 38 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 58bd85ac6..24450379c 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -4,8 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 7 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 8 | 11 | ||
| 12 | #include "core/core.h" | ||
| 9 | #include "core/mem_map.h" | 13 | #include "core/mem_map.h" |
| 10 | 14 | ||
| 11 | #include "core/hle/kernel/kernel.h" | 15 | #include "core/hle/kernel/kernel.h" |
| @@ -48,69 +52,102 @@ enum WaitType { | |||
| 48 | 52 | ||
| 49 | namespace Kernel { | 53 | namespace Kernel { |
| 50 | 54 | ||
| 51 | /// Creates a new thread - wrapper for external user | 55 | class Thread : public Kernel::Object { |
| 52 | Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id, | 56 | public: |
| 53 | u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE); | 57 | static ResultVal<Thread*> Create(const char* name, u32 entry_point, s32 priority, u32 arg, |
| 58 | s32 processor_id, u32 stack_top, int stack_size = Kernel::DEFAULT_STACK_SIZE); | ||
| 54 | 59 | ||
| 55 | /// Sets up the primary application thread | 60 | std::string GetName() const override { return name; } |
| 56 | Handle SetupMainThread(s32 priority, int stack_size=Kernel::DEFAULT_STACK_SIZE); | 61 | std::string GetTypeName() const override { return "Thread"; } |
| 57 | 62 | ||
| 58 | /// Reschedules to the next available thread (call after current thread is suspended) | 63 | static const HandleType HANDLE_TYPE = HandleType::Thread; |
| 59 | void Reschedule(); | 64 | HandleType GetHandleType() const override { return HANDLE_TYPE; } |
| 60 | 65 | ||
| 61 | /// Stops the current thread | 66 | inline bool IsRunning() const { return (status & THREADSTATUS_RUNNING) != 0; } |
| 62 | ResultCode StopThread(Handle thread, const char* reason); | 67 | inline bool IsStopped() const { return (status & THREADSTATUS_DORMANT) != 0; } |
| 68 | inline bool IsReady() const { return (status & THREADSTATUS_READY) != 0; } | ||
| 69 | inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; } | ||
| 70 | inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; } | ||
| 71 | inline bool IsIdle() const { return idle; } | ||
| 63 | 72 | ||
| 64 | /** | 73 | ResultVal<bool> WaitSynchronization() override; |
| 65 | * Retrieves the ID of the specified thread handle | 74 | |
| 66 | * @param thread_id Will contain the output thread id | 75 | s32 GetPriority() const { return current_priority; } |
| 67 | * @param handle Handle to the thread we want | 76 | void SetPriority(s32 priority); |
| 68 | * @return Whether the function was successful or not | 77 | |
| 69 | */ | 78 | u32 GetThreadId() const { return thread_id; } |
| 70 | ResultCode GetThreadId(u32* thread_id, Handle handle); | 79 | |
| 80 | void Stop(const char* reason); | ||
| 81 | /// Resumes a thread from waiting by marking it as "ready". | ||
| 82 | void ResumeFromWait(); | ||
| 83 | |||
| 84 | Core::ThreadContext context; | ||
| 85 | |||
| 86 | u32 thread_id; | ||
| 87 | |||
| 88 | u32 status; | ||
| 89 | u32 entry_point; | ||
| 90 | u32 stack_top; | ||
| 91 | u32 stack_size; | ||
| 92 | |||
| 93 | s32 initial_priority; | ||
| 94 | s32 current_priority; | ||
| 95 | |||
| 96 | s32 processor_id; | ||
| 71 | 97 | ||
| 72 | /// Resumes a thread from waiting by marking it as "ready" | 98 | WaitType wait_type; |
| 73 | void ResumeThreadFromWait(Handle handle); | 99 | Object* wait_object; |
| 100 | VAddr wait_address; | ||
| 101 | |||
| 102 | std::vector<Thread*> waiting_threads; // TODO(yuriks): Owned | ||
| 103 | |||
| 104 | std::string name; | ||
| 105 | |||
| 106 | /// Whether this thread is intended to never actually be executed, i.e. always idle | ||
| 107 | bool idle = false; | ||
| 108 | |||
| 109 | private: | ||
| 110 | Thread() = default; | ||
| 111 | }; | ||
| 112 | |||
| 113 | /// Sets up the primary application thread | ||
| 114 | Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZE); | ||
| 115 | |||
| 116 | /// Reschedules to the next available thread (call after current thread is suspended) | ||
| 117 | void Reschedule(); | ||
| 74 | 118 | ||
| 75 | /// Arbitrate the highest priority thread that is waiting | 119 | /// Arbitrate the highest priority thread that is waiting |
| 76 | Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address); | 120 | Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address); |
| 77 | 121 | ||
| 78 | /// Arbitrate all threads currently waiting... | 122 | /// Arbitrate all threads currently waiting... |
| 79 | void ArbitrateAllThreads(u32 arbiter, u32 address); | 123 | void ArbitrateAllThreads(Object* arbiter, u32 address); |
| 80 | 124 | ||
| 81 | /// Gets the current thread handle | 125 | /// Gets the current thread |
| 82 | Handle GetCurrentThreadHandle(); | 126 | Thread* GetCurrentThread(); |
| 83 | 127 | ||
| 84 | /** | 128 | /** |
| 85 | * Puts the current thread in the wait state for the given type | 129 | * Puts the current thread in the wait state for the given type |
| 86 | * @param wait_type Type of wait | 130 | * @param wait_type Type of wait |
| 87 | * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread | 131 | * @param wait_object Kernel object that we are waiting on, defaults to current thread |
| 88 | */ | 132 | */ |
| 89 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); | 133 | void WaitCurrentThread(WaitType wait_type, Object* wait_object = GetCurrentThread()); |
| 90 | 134 | ||
| 91 | /** | 135 | /** |
| 92 | * Schedules an event to wake up the specified thread after the specified delay. | 136 | * Schedules an event to wake up the specified thread after the specified delay. |
| 93 | * @param handle The thread handle. | 137 | * @param handle The thread handle. |
| 94 | * @param nanoseconds The time this thread will be allowed to sleep for. | 138 | * @param nanoseconds The time this thread will be allowed to sleep for. |
| 95 | */ | 139 | */ |
| 96 | void WakeThreadAfterDelay(Handle handle, s64 nanoseconds); | 140 | void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds); |
| 97 | 141 | ||
| 98 | /** | 142 | /** |
| 99 | * Puts the current thread in the wait state for the given type | 143 | * Puts the current thread in the wait state for the given type |
| 100 | * @param wait_type Type of wait | 144 | * @param wait_type Type of wait |
| 101 | * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread | 145 | * @param wait_object Kernel object that we are waiting on |
| 102 | * @param wait_address Arbitration address used to resume from wait | 146 | * @param wait_address Arbitration address used to resume from wait |
| 103 | */ | 147 | */ |
| 104 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address); | 148 | void WaitCurrentThread(WaitType wait_type, Object* wait_object, VAddr wait_address); |
| 105 | 149 | ||
| 106 | /// Put current thread in a wait state - on WaitSynchronization | ||
| 107 | void WaitThread_Synchronization(); | ||
| 108 | 150 | ||
| 109 | /// Get the priority of the thread specified by handle | ||
| 110 | ResultVal<u32> GetThreadPriority(const Handle handle); | ||
| 111 | |||
| 112 | /// Set the priority of the thread specified by handle | ||
| 113 | ResultCode SetThreadPriority(Handle handle, s32 priority); | ||
| 114 | 151 | ||
| 115 | /** | 152 | /** |
| 116 | * Sets up the idle thread, this is a thread that is intended to never execute instructions, | 153 | * Sets up the idle thread, this is a thread that is intended to never execute instructions, |
| @@ -119,10 +156,6 @@ ResultCode SetThreadPriority(Handle handle, s32 priority); | |||
| 119 | * @returns The handle of the idle thread | 156 | * @returns The handle of the idle thread |
| 120 | */ | 157 | */ |
| 121 | Handle SetupIdleThread(); | 158 | Handle SetupIdleThread(); |
| 122 | |||
| 123 | /// Whether the current thread is an idle thread | ||
| 124 | bool IsIdleThread(Handle thread); | ||
| 125 | |||
| 126 | /// Initialize threading | 159 | /// Initialize threading |
| 127 | void ThreadingInit(); | 160 | void ThreadingInit(); |
| 128 | 161 | ||