summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar Lioncash2018-10-03 18:47:57 -0400
committerGravatar Lioncash2018-10-04 00:14:15 -0400
commitbaed7e1fba99c3f1932c6a41ad1496d1b6490a5a (patch)
tree004a9784a05294531e2f3975205f856a96b1a1ef /src/core/hle/kernel/thread.h
parentMerge pull request #1330 from raven02/tlds (diff)
downloadyuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.gz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.xz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.zip
kernel/thread: Make all instance variables private
Many of the member variables of the thread class aren't even used outside of the class itself, so there's no need to make those variables public. This change follows in the steps of the previous changes that made other kernel types' members private. The main motivation behind this is that the Thread class will likely change in the future as emulation becomes more accurate, and letting random bits of the emulator access data members of the Thread class directly makes it a pain to shuffle around and/or modify internals. Having all data members public like this also makes it difficult to reason about certain bits of behavior without first verifying what parts of the core actually use them. Everything being public also generally follows the tendency for changes to be introduced in completely different translation units that would otherwise be better introduced as an addition to the Thread class' public interface.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h216
1 files changed, 181 insertions, 35 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 4250144c3..d2b191357 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -65,6 +65,15 @@ public:
65 using TLSMemory = std::vector<u8>; 65 using TLSMemory = std::vector<u8>;
66 using TLSMemoryPtr = std::shared_ptr<TLSMemory>; 66 using TLSMemoryPtr = std::shared_ptr<TLSMemory>;
67 67
68 using MutexWaitingThreads = std::vector<SharedPtr<Thread>>;
69
70 using ThreadContext = Core::ARM_Interface::ThreadContext;
71
72 using ThreadWaitObjects = std::vector<SharedPtr<WaitObject>>;
73
74 using WakeupCallback = std::function<bool(ThreadWakeupReason reason, SharedPtr<Thread> thread,
75 SharedPtr<WaitObject> object, std::size_t index)>;
76
68 /** 77 /**
69 * Creates and returns a new thread. The new thread is immediately scheduled 78 * Creates and returns a new thread. The new thread is immediately scheduled
70 * @param kernel The kernel instance this thread will be created under. 79 * @param kernel The kernel instance this thread will be created under.
@@ -106,6 +115,14 @@ public:
106 } 115 }
107 116
108 /** 117 /**
118 * Gets the thread's nominal priority.
119 * @return The current thread's nominal priority.
120 */
121 u32 GetNominalPriority() const {
122 return nominal_priority;
123 }
124
125 /**
109 * Sets the thread's current priority 126 * Sets the thread's current priority
110 * @param priority The new priority 127 * @param priority The new priority
111 */ 128 */
@@ -133,7 +150,7 @@ public:
133 * Gets the thread's thread ID 150 * Gets the thread's thread ID
134 * @return The thread's ID 151 * @return The thread's ID
135 */ 152 */
136 u32 GetThreadId() const { 153 u32 GetThreadID() const {
137 return thread_id; 154 return thread_id;
138 } 155 }
139 156
@@ -203,6 +220,11 @@ public:
203 return tpidr_el0; 220 return tpidr_el0;
204 } 221 }
205 222
223 /// Sets the value of the TPIDR_EL0 Read/Write system register for this thread.
224 void SetTPIDR_EL0(u64 value) {
225 tpidr_el0 = value;
226 }
227
206 /* 228 /*
207 * Returns the address of the current thread's command buffer, located in the TLS. 229 * Returns the address of the current thread's command buffer, located in the TLS.
208 * @returns VAddr of the thread's command buffer. 230 * @returns VAddr of the thread's command buffer.
@@ -218,69 +240,193 @@ public:
218 return status == ThreadStatus::WaitSynchAll; 240 return status == ThreadStatus::WaitSynchAll;
219 } 241 }
220 242
221 Core::ARM_Interface::ThreadContext context; 243 ThreadContext& GetContext() {
244 return context;
245 }
246
247 const ThreadContext& GetContext() const {
248 return context;
249 }
250
251 ThreadStatus GetStatus() const {
252 return status;
253 }
254
255 void SetStatus(ThreadStatus new_status);
256
257 u64 GetLastRunningTicks() const {
258 return last_running_ticks;
259 }
260
261 s32 GetProcessorID() const {
262 return processor_id;
263 }
264
265 SharedPtr<Process>& GetOwnerProcess() {
266 return owner_process;
267 }
268
269 const SharedPtr<Process>& GetOwnerProcess() const {
270 return owner_process;
271 }
272
273 const ThreadWaitObjects& GetWaitObjects() const {
274 return wait_objects;
275 }
276
277 void SetWaitObjects(ThreadWaitObjects objects) {
278 wait_objects = std::move(objects);
279 }
280
281 void ClearWaitObjects() {
282 wait_objects.clear();
283 }
284
285 /// Determines whether all the objects this thread is waiting on are ready.
286 bool AllWaitObjectsReady();
287
288 const MutexWaitingThreads& GetMutexWaitingThreads() const {
289 return wait_mutex_threads;
290 }
291
292 Thread* GetLockOwner() const {
293 return lock_owner.get();
294 }
295
296 void SetLockOwner(SharedPtr<Thread> owner) {
297 lock_owner = std::move(owner);
298 }
299
300 VAddr GetCondVarWaitAddress() const {
301 return condvar_wait_address;
302 }
303
304 void SetCondVarWaitAddress(VAddr address) {
305 condvar_wait_address = address;
306 }
307
308 VAddr GetMutexWaitAddress() const {
309 return mutex_wait_address;
310 }
222 311
223 u32 thread_id; 312 void SetMutexWaitAddress(VAddr address) {
313 mutex_wait_address = address;
314 }
224 315
225 ThreadStatus status; 316 Handle GetWaitHandle() const {
226 VAddr entry_point; 317 return wait_handle;
227 VAddr stack_top; 318 }
228 319
229 u32 nominal_priority; ///< Nominal thread priority, as set by the emulated application 320 void SetWaitHandle(Handle handle) {
230 u32 current_priority; ///< Current thread priority, can be temporarily changed 321 wait_handle = handle;
322 }
231 323
232 u64 last_running_ticks; ///< CPU tick when thread was last running 324 VAddr GetArbiterWaitAddress() const {
325 return arb_wait_address;
326 }
233 327
234 s32 processor_id; 328 void SetArbiterWaitAddress(VAddr address) {
329 arb_wait_address = address;
330 }
235 331
236 VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread 332 void SetGuestHandle(Handle handle) {
237 u64 tpidr_el0; ///< TPIDR_EL0 read/write system register. 333 guest_handle = handle;
334 }
238 335
239 SharedPtr<Process> owner_process; ///< Process that owns this thread 336 bool HasWakeupCallback() const {
337 return wakeup_callback != nullptr;
338 }
339
340 void SetWakeupCallback(WakeupCallback callback) {
341 wakeup_callback = std::move(callback);
342 }
343
344 void InvalidateWakeupCallback() {
345 SetWakeupCallback(nullptr);
346 }
347
348 /**
349 * Invokes the thread's wakeup callback.
350 *
351 * @pre A valid wakeup callback has been set. Violating this precondition
352 * will cause an assertion to trigger.
353 */
354 bool InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread,
355 SharedPtr<WaitObject> object, std::size_t index);
356
357 u32 GetIdealCore() const {
358 return ideal_core;
359 }
360
361 u64 GetAffinityMask() const {
362 return affinity_mask;
363 }
364
365private:
366 explicit Thread(KernelCore& kernel);
367 ~Thread() override;
368
369 Core::ARM_Interface::ThreadContext context{};
370
371 u32 thread_id = 0;
372
373 ThreadStatus status = ThreadStatus::Dormant;
374
375 VAddr entry_point = 0;
376 VAddr stack_top = 0;
377
378 u32 nominal_priority = 0; ///< Nominal thread priority, as set by the emulated application
379 u32 current_priority = 0; ///< Current thread priority, can be temporarily changed
380
381 u64 last_running_ticks = 0; ///< CPU tick when thread was last running
382
383 s32 processor_id = 0;
384
385 VAddr tls_address = 0; ///< Virtual address of the Thread Local Storage of the thread
386 u64 tpidr_el0 = 0; ///< TPIDR_EL0 read/write system register.
387
388 /// Process that owns this thread
389 SharedPtr<Process> owner_process;
240 390
241 /// Objects that the thread is waiting on, in the same order as they were 391 /// Objects that the thread is waiting on, in the same order as they were
242 // passed to WaitSynchronization1/N. 392 /// passed to WaitSynchronization1/N.
243 std::vector<SharedPtr<WaitObject>> wait_objects; 393 ThreadWaitObjects wait_objects;
244 394
245 /// List of threads that are waiting for a mutex that is held by this thread. 395 /// List of threads that are waiting for a mutex that is held by this thread.
246 std::vector<SharedPtr<Thread>> wait_mutex_threads; 396 MutexWaitingThreads wait_mutex_threads;
247 397
248 /// Thread that owns the lock that this thread is waiting for. 398 /// Thread that owns the lock that this thread is waiting for.
249 SharedPtr<Thread> lock_owner; 399 SharedPtr<Thread> lock_owner;
250 400
251 // If waiting on a ConditionVariable, this is the ConditionVariable address 401 /// If waiting on a ConditionVariable, this is the ConditionVariable address
252 VAddr condvar_wait_address; 402 VAddr condvar_wait_address = 0;
253 VAddr mutex_wait_address; ///< If waiting on a Mutex, this is the mutex address 403 /// If waiting on a Mutex, this is the mutex address
254 Handle wait_handle; ///< The handle used to wait for the mutex. 404 VAddr mutex_wait_address = 0;
405 /// The handle used to wait for the mutex.
406 Handle wait_handle = 0;
255 407
256 // If waiting for an AddressArbiter, this is the address being waited on. 408 /// If waiting for an AddressArbiter, this is the address being waited on.
257 VAddr arb_wait_address{0}; 409 VAddr arb_wait_address{0};
258 410
259 std::string name;
260
261 /// Handle used by guest emulated application to access this thread 411 /// Handle used by guest emulated application to access this thread
262 Handle guest_handle; 412 Handle guest_handle = 0;
263 413
264 /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. 414 /// Handle used as userdata to reference this object when inserting into the CoreTiming queue.
265 Handle callback_handle; 415 Handle callback_handle = 0;
266 416
267 using WakeupCallback = bool(ThreadWakeupReason reason, SharedPtr<Thread> thread, 417 /// Callback that will be invoked when the thread is resumed from a waiting state. If the thread
268 SharedPtr<WaitObject> object, std::size_t index); 418 /// was waiting via WaitSynchronizationN then the object will be the last object that became
269 // Callback that will be invoked when the thread is resumed from a waiting state. If the thread 419 /// available. In case of a timeout, the object will be nullptr.
270 // was waiting via WaitSynchronizationN then the object will be the last object that became 420 WakeupCallback wakeup_callback;
271 // available. In case of a timeout, the object will be nullptr.
272 std::function<WakeupCallback> wakeup_callback;
273 421
274 std::shared_ptr<Scheduler> scheduler; 422 std::shared_ptr<Scheduler> scheduler;
275 423
276 u32 ideal_core{0xFFFFFFFF}; 424 u32 ideal_core{0xFFFFFFFF};
277 u64 affinity_mask{0x1}; 425 u64 affinity_mask{0x1};
278 426
279private:
280 explicit Thread(KernelCore& kernel);
281 ~Thread() override;
282
283 TLSMemoryPtr tls_memory = std::make_shared<TLSMemory>(); 427 TLSMemoryPtr tls_memory = std::make_shared<TLSMemory>();
428
429 std::string name;
284}; 430};
285 431
286/** 432/**