summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar bunnei2020-12-28 13:16:43 -0800
committerGravatar bunnei2021-01-11 14:23:16 -0800
commitc3c43e32fcf198444acb493483e03fcb193156df (patch)
treea516e116d7dbb9309b0adbfa2e3660861ff4e6b7 /src/core/hle/kernel/thread.h
parentcore: hle: kernel: Add some useful functions for checking kernel addresses. (diff)
downloadyuzu-c3c43e32fcf198444acb493483e03fcb193156df.tar.gz
yuzu-c3c43e32fcf198444acb493483e03fcb193156df.tar.xz
yuzu-c3c43e32fcf198444acb493483e03fcb193156df.zip
hle: kernel: thread: Replace ThreadStatus/ThreadSchedStatus with a single ThreadState.
- This is how the real kernel works, and is more accurate and simpler.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h75
1 files changed, 34 insertions, 41 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 69458548b..06dd2ef2d 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -73,19 +73,26 @@ enum ThreadProcessorId : s32 {
73 (1 << THREADPROCESSORID_2) | (1 << THREADPROCESSORID_3) 73 (1 << THREADPROCESSORID_2) | (1 << THREADPROCESSORID_3)
74}; 74};
75 75
76enum class ThreadStatus { 76enum class ThreadState : u16 {
77 Ready, ///< Ready to run 77 Initialized = 0,
78 Paused, ///< Paused by SetThreadActivity or debug 78 Waiting = 1,
79 WaitHLEEvent, ///< Waiting for hle event to finish 79 Runnable = 2,
80 WaitSleep, ///< Waiting due to a SleepThread SVC 80 Terminated = 3,
81 WaitIPC, ///< Waiting for the reply from an IPC request 81
82 WaitSynch, ///< Waiting due to WaitSynchronization 82 SuspendShift = 4,
83 WaitMutex, ///< Waiting due to an ArbitrateLock svc 83 Mask = (1 << SuspendShift) - 1,
84 WaitCondVar, ///< Waiting due to an WaitProcessWideKey svc 84
85 WaitArb, ///< Waiting due to a SignalToAddress/WaitForAddress svc 85 ProcessSuspended = (1 << (0 + SuspendShift)),
86 Dormant, ///< Created but not yet made ready 86 ThreadSuspended = (1 << (1 + SuspendShift)),
87 Dead ///< Run to completion, or forcefully terminated 87 DebugSuspended = (1 << (2 + SuspendShift)),
88 BacktraceSuspended = (1 << (3 + SuspendShift)),
89 InitSuspended = (1 << (4 + SuspendShift)),
90
91 SuspendFlagMask = ((1 << 5) - 1) << SuspendShift,
92
93 HighMask = 0xfff0,
88}; 94};
95DECLARE_ENUM_FLAG_OPERATORS(ThreadState);
89 96
90enum class ThreadWakeupReason { 97enum class ThreadWakeupReason {
91 Signal, // The thread was woken up by WakeupAllWaitingThreads due to an object signal. 98 Signal, // The thread was woken up by WakeupAllWaitingThreads due to an object signal.
@@ -97,13 +104,6 @@ enum class ThreadActivity : u32 {
97 Paused = 1, 104 Paused = 1,
98}; 105};
99 106
100enum class ThreadSchedStatus : u32 {
101 None = 0,
102 Paused = 1,
103 Runnable = 2,
104 Exited = 3,
105};
106
107enum class ThreadSchedFlags : u32 { 107enum class ThreadSchedFlags : u32 {
108 ProcessPauseFlag = 1 << 4, 108 ProcessPauseFlag = 1 << 4,
109 ThreadPauseFlag = 1 << 5, 109 ThreadPauseFlag = 1 << 5,
@@ -111,12 +111,6 @@ enum class ThreadSchedFlags : u32 {
111 KernelInitPauseFlag = 1 << 8, 111 KernelInitPauseFlag = 1 << 8,
112}; 112};
113 113
114enum class ThreadSchedMasks : u32 {
115 LowMask = 0x000f,
116 HighMask = 0xfff0,
117 ForcePauseMask = 0x0070,
118};
119
120class Thread final : public KSynchronizationObject { 114class Thread final : public KSynchronizationObject {
121public: 115public:
122 explicit Thread(KernelCore& kernel); 116 explicit Thread(KernelCore& kernel);
@@ -326,11 +320,19 @@ public:
326 320
327 std::shared_ptr<Common::Fiber>& GetHostContext(); 321 std::shared_ptr<Common::Fiber>& GetHostContext();
328 322
329 ThreadStatus GetStatus() const { 323 ThreadState GetState() const {
330 return status; 324 return thread_state & ThreadState::Mask;
331 } 325 }
332 326
333 void SetState(ThreadStatus new_status); 327 ThreadState GetRawState() const {
328 return thread_state;
329 }
330
331 void SetState(ThreadState new_state);
332
333 void SetWaitingCondVar(bool value) {
334 is_waiting_on_condvar = value;
335 }
334 336
335 s64 GetLastScheduledTick() const { 337 s64 GetLastScheduledTick() const {
336 return this->last_scheduled_tick; 338 return this->last_scheduled_tick;
@@ -447,15 +449,6 @@ public:
447 this->schedule_count = count; 449 this->schedule_count = count;
448 } 450 }
449 451
450 ThreadSchedStatus GetState() const {
451 return static_cast<ThreadSchedStatus>(scheduling_state &
452 static_cast<u32>(ThreadSchedMasks::LowMask));
453 }
454
455 bool IsRunnable() const {
456 return scheduling_state == static_cast<u32>(ThreadSchedStatus::Runnable);
457 }
458
459 bool IsRunning() const { 452 bool IsRunning() const {
460 return is_running; 453 return is_running;
461 } 454 }
@@ -497,7 +490,7 @@ public:
497 } 490 }
498 491
499 bool IsTerminationRequested() const { 492 bool IsTerminationRequested() const {
500 return will_be_terminated || GetState() == ThreadSchedStatus::Exited; 493 return will_be_terminated || GetState() == ThreadState::Terminated;
501 } 494 }
502 495
503 bool IsPaused() const { 496 bool IsPaused() const {
@@ -590,7 +583,7 @@ private:
590 friend class KScheduler; 583 friend class KScheduler;
591 friend class Process; 584 friend class Process;
592 585
593 void SetSchedulingStatus(ThreadSchedStatus new_status); 586 void SetSchedulingStatus(ThreadState new_status);
594 void AddSchedulingFlag(ThreadSchedFlags flag); 587 void AddSchedulingFlag(ThreadSchedFlags flag);
595 void RemoveSchedulingFlag(ThreadSchedFlags flag); 588 void RemoveSchedulingFlag(ThreadSchedFlags flag);
596 void SetCurrentPriority(u32 new_priority); 589 void SetCurrentPriority(u32 new_priority);
@@ -600,8 +593,7 @@ private:
600 ThreadContext64 context_64{}; 593 ThreadContext64 context_64{};
601 std::shared_ptr<Common::Fiber> host_context{}; 594 std::shared_ptr<Common::Fiber> host_context{};
602 595
603 ThreadStatus status = ThreadStatus::Dormant; 596 ThreadState thread_state = ThreadState::Initialized;
604 u32 scheduling_state = 0;
605 597
606 u64 thread_id = 0; 598 u64 thread_id = 0;
607 599
@@ -647,6 +639,7 @@ private:
647 639
648 /// If waiting on a ConditionVariable, this is the ConditionVariable address 640 /// If waiting on a ConditionVariable, this is the ConditionVariable address
649 VAddr condvar_wait_address = 0; 641 VAddr condvar_wait_address = 0;
642 bool is_waiting_on_condvar{};
650 /// If waiting on a Mutex, this is the mutex address 643 /// If waiting on a Mutex, this is the mutex address
651 VAddr mutex_wait_address = 0; 644 VAddr mutex_wait_address = 0;
652 /// The handle used to wait for the mutex. 645 /// The handle used to wait for the mutex.