summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h109
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
49namespace Kernel { 53namespace Kernel {
50 54
51/// Creates a new thread - wrapper for external user 55class Thread : public Kernel::Object {
52Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id, 56public:
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; }
56Handle 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;
59void 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; }
62ResultCode 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; }
70ResultCode 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;
73void 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
109private:
110 Thread() = default;
111};
112
113/// Sets up the primary application thread
114Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZE);
115
116/// Reschedules to the next available thread (call after current thread is suspended)
117void Reschedule();
74 118
75/// Arbitrate the highest priority thread that is waiting 119/// Arbitrate the highest priority thread that is waiting
76Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address); 120Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address);
77 121
78/// Arbitrate all threads currently waiting... 122/// Arbitrate all threads currently waiting...
79void ArbitrateAllThreads(u32 arbiter, u32 address); 123void ArbitrateAllThreads(Object* arbiter, u32 address);
80 124
81/// Gets the current thread handle 125/// Gets the current thread
82Handle GetCurrentThreadHandle(); 126Thread* 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 */
89void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); 133void 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 */
96void WakeThreadAfterDelay(Handle handle, s64 nanoseconds); 140void 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 */
104void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address); 148void WaitCurrentThread(WaitType wait_type, Object* wait_object, VAddr wait_address);
105 149
106/// Put current thread in a wait state - on WaitSynchronization
107void WaitThread_Synchronization();
108 150
109/// Get the priority of the thread specified by handle
110ResultVal<u32> GetThreadPriority(const Handle handle);
111
112/// Set the priority of the thread specified by handle
113ResultCode 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 */
121Handle SetupIdleThread(); 158Handle SetupIdleThread();
122
123/// Whether the current thread is an idle thread
124bool IsIdleThread(Handle thread);
125
126/// Initialize threading 159/// Initialize threading
127void ThreadingInit(); 160void ThreadingInit();
128 161