summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-22 11:07:22 -0200
committerGravatar Yuri Kunde Schlesner2015-01-09 04:02:15 -0200
commit9bf8462b96d34b30f62b8aca745dd558e7f0a450 (patch)
tree32606d5176a82daa4e59bb47bede34d4a941780a /src/core/hle/kernel/thread.h
parentKernel: Move Thread's definition to the header file (diff)
downloadyuzu-9bf8462b96d34b30f62b8aca745dd558e7f0a450.tar.gz
yuzu-9bf8462b96d34b30f62b8aca745dd558e7f0a450.tar.xz
yuzu-9bf8462b96d34b30f62b8aca745dd558e7f0a450.zip
Thread: Reduce use of Handles and move some funcs to inside the class.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h68
1 files changed, 22 insertions, 46 deletions
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 {
54 54
55class Thread : public Kernel::Object { 55class Thread : public Kernel::Object {
56public: 56public:
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);
59
57 std::string GetName() const override { return name; } 60 std::string GetName() const override { return name; }
58 std::string GetTypeName() const override { return "Thread"; } 61 std::string GetTypeName() const override { return "Thread"; }
59 62
@@ -69,6 +72,15 @@ public:
69 72
70 ResultVal<bool> WaitSynchronization() override; 73 ResultVal<bool> WaitSynchronization() override;
71 74
75 s32 GetPriority() const { return current_priority; }
76 void SetPriority(s32 priority);
77
78 u32 GetThreadId() const { return thread_id; }
79
80 void Stop(const char* reason);
81 /// Resumes a thread from waiting by marking it as "ready".
82 void ResumeFromWait();
83
72 Core::ThreadContext context; 84 Core::ThreadContext context;
73 85
74 u32 thread_id; 86 u32 thread_id;
@@ -84,10 +96,10 @@ public:
84 s32 processor_id; 96 s32 processor_id;
85 97
86 WaitType wait_type; 98 WaitType wait_type;
87 Handle wait_handle; 99 Object* wait_object;
88 VAddr wait_address; 100 VAddr wait_address;
89 101
90 std::vector<Handle> waiting_threads; 102 std::vector<Thread*> waiting_threads; // TODO(yuriks): Owned
91 103
92 std::string name; 104 std::string name;
93 105
@@ -95,79 +107,47 @@ public:
95 bool idle = false; 107 bool idle = false;
96 108
97private: 109private:
98 // TODO(yuriks) Temporary until the creation logic can be moved into a static function
99 friend Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 priority,
100 s32 processor_id, u32 stack_top, int stack_size);
101
102 Thread() = default; 110 Thread() = default;
103}; 111};
104 112
105/// Creates a new thread - wrapper for external user
106Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id,
107 u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE);
108
109/// Sets up the primary application thread 113/// Sets up the primary application thread
110Handle SetupMainThread(s32 priority, int stack_size=Kernel::DEFAULT_STACK_SIZE); 114Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZE);
111 115
112/// Reschedules to the next available thread (call after current thread is suspended) 116/// Reschedules to the next available thread (call after current thread is suspended)
113void Reschedule(); 117void Reschedule();
114 118
115/// Stops the current thread
116ResultCode StopThread(Handle thread, const char* reason);
117
118/**
119 * Retrieves the ID of the specified thread handle
120 * @param thread_id Will contain the output thread id
121 * @param handle Handle to the thread we want
122 * @return Whether the function was successful or not
123 */
124ResultCode GetThreadId(u32* thread_id, Handle handle);
125
126/// Resumes a thread from waiting by marking it as "ready"
127void ResumeThreadFromWait(Handle handle);
128
129/// Arbitrate the highest priority thread that is waiting 119/// Arbitrate the highest priority thread that is waiting
130Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address); 120Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address);
131 121
132/// Arbitrate all threads currently waiting... 122/// Arbitrate all threads currently waiting...
133void ArbitrateAllThreads(u32 arbiter, u32 address); 123void ArbitrateAllThreads(Object* arbiter, u32 address);
134 124
135/// Gets the current thread 125/// Gets the current thread
136Thread* GetCurrentThread(); 126Thread* GetCurrentThread();
137 127
138/// Gets the current thread handle
139Handle GetCurrentThreadHandle();
140
141/** 128/**
142 * 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
143 * @param wait_type Type of wait 130 * @param wait_type Type of wait
144 * @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
145 */ 132 */
146void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); 133void WaitCurrentThread(WaitType wait_type, Object* wait_object = GetCurrentThread());
147 134
148/** 135/**
149 * 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.
150 * @param handle The thread handle. 137 * @param handle The thread handle.
151 * @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.
152 */ 139 */
153void WakeThreadAfterDelay(Handle handle, s64 nanoseconds); 140void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds);
154 141
155/** 142/**
156 * 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
157 * @param wait_type Type of wait 144 * @param wait_type Type of wait
158 * @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
159 * @param wait_address Arbitration address used to resume from wait 146 * @param wait_address Arbitration address used to resume from wait
160 */ 147 */
161void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address); 148void WaitCurrentThread(WaitType wait_type, Object* wait_object, VAddr wait_address);
162 149
163/// Put current thread in a wait state - on WaitSynchronization
164void WaitThread_Synchronization();
165 150
166/// Get the priority of the thread specified by handle
167ResultVal<u32> GetThreadPriority(const Handle handle);
168
169/// Set the priority of the thread specified by handle
170ResultCode SetThreadPriority(Handle handle, s32 priority);
171 151
172/** 152/**
173 * 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,
@@ -176,10 +156,6 @@ ResultCode SetThreadPriority(Handle handle, s32 priority);
176 * @returns The handle of the idle thread 156 * @returns The handle of the idle thread
177 */ 157 */
178Handle SetupIdleThread(); 158Handle SetupIdleThread();
179
180/// Whether the current thread is an idle thread
181bool IsIdleThread(Handle thread);
182
183/// Initialize threading 159/// Initialize threading
184void ThreadingInit(); 160void ThreadingInit();
185 161