summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-22 04:32:03 -0200
committerGravatar Yuri Kunde Schlesner2015-01-09 03:51:55 -0200
commitba72208cd4905410eab8b996da0fa05fd05c72ff (patch)
tree3dcaf53894232e83741d3a524c7c53b8da60409c /src
parentMove ThreadContext to core/core.h and deal with the fallout (diff)
downloadyuzu-ba72208cd4905410eab8b996da0fa05fd05c72ff.tar.gz
yuzu-ba72208cd4905410eab8b996da0fa05fd05c72ff.tar.xz
yuzu-ba72208cd4905410eab8b996da0fa05fd05c72ff.zip
Kernel: Move Thread's definition to the header file
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/kernel.cpp3
-rw-r--r--src/core/hle/kernel/thread.cpp60
-rw-r--r--src/core/hle/kernel/thread.h57
3 files changed, 67 insertions, 53 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 1537702cf..5dfc41bab 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -81,8 +81,7 @@ bool HandleTable::IsValid(Handle handle) const {
81 81
82Object* HandleTable::GetGeneric(Handle handle) const { 82Object* HandleTable::GetGeneric(Handle handle) const {
83 if (handle == CurrentThread) { 83 if (handle == CurrentThread) {
84 // TODO(yuriks) Directly return the pointer once this is possible. 84 return GetCurrentThread();
85 handle = GetCurrentThreadHandle();
86 } else if (handle == CurrentProcess) { 85 } else if (handle == CurrentProcess) {
87 LOG_ERROR(Kernel, "Current process (%08X) pseudo-handle not supported", CurrentProcess); 86 LOG_ERROR(Kernel, "Current process (%08X) pseudo-handle not supported", CurrentProcess);
88 return nullptr; 87 return nullptr;
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 3e9ea464d..ef63c5f41 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -22,60 +22,18 @@
22 22
23namespace Kernel { 23namespace Kernel {
24 24
25class Thread : public Kernel::Object { 25ResultVal<bool> Thread::WaitSynchronization() {
26public: 26 const bool wait = status != THREADSTATUS_DORMANT;
27 27 if (wait) {
28 std::string GetName() const override { return name; } 28 Handle thread = GetCurrentThreadHandle();
29 std::string GetTypeName() const override { return "Thread"; } 29 if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
30 30 waiting_threads.push_back(thread);
31 static const HandleType HANDLE_TYPE = HandleType::Thread;
32 HandleType GetHandleType() const override { return HANDLE_TYPE; }
33
34 inline bool IsRunning() const { return (status & THREADSTATUS_RUNNING) != 0; }
35 inline bool IsStopped() const { return (status & THREADSTATUS_DORMANT) != 0; }
36 inline bool IsReady() const { return (status & THREADSTATUS_READY) != 0; }
37 inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; }
38 inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; }
39 inline bool IsIdle() const { return idle; }
40
41 ResultVal<bool> WaitSynchronization() override {
42 const bool wait = status != THREADSTATUS_DORMANT;
43 if (wait) {
44 Handle thread = GetCurrentThreadHandle();
45 if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
46 waiting_threads.push_back(thread);
47 }
48 WaitCurrentThread(WAITTYPE_THREADEND, this->GetHandle());
49 } 31 }
50 32 WaitCurrentThread(WAITTYPE_THREADEND, this->GetHandle());
51 return MakeResult<bool>(wait);
52 } 33 }
53 34
54 Core::ThreadContext context; 35 return MakeResult<bool>(wait);
55 36}
56 u32 thread_id;
57
58 u32 status;
59 u32 entry_point;
60 u32 stack_top;
61 u32 stack_size;
62
63 s32 initial_priority;
64 s32 current_priority;
65
66 s32 processor_id;
67
68 WaitType wait_type;
69 Handle wait_handle;
70 VAddr wait_address;
71
72 std::vector<Handle> waiting_threads;
73
74 std::string name;
75
76 /// Whether this thread is intended to never actually be executed, i.e. always idle
77 bool idle = false;
78};
79 37
80// Lists all thread ids that aren't deleted/etc. 38// Lists all thread ids that aren't deleted/etc.
81static std::vector<Handle> thread_queue; 39static std::vector<Handle> thread_queue;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 58bd85ac6..51290975e 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,6 +52,56 @@ enum WaitType {
48 52
49namespace Kernel { 53namespace Kernel {
50 54
55class Thread : public Kernel::Object {
56public:
57 std::string GetName() const override { return name; }
58 std::string GetTypeName() const override { return "Thread"; }
59
60 static const HandleType HANDLE_TYPE = HandleType::Thread;
61 HandleType GetHandleType() const override { return HANDLE_TYPE; }
62
63 inline bool IsRunning() const { return (status & THREADSTATUS_RUNNING) != 0; }
64 inline bool IsStopped() const { return (status & THREADSTATUS_DORMANT) != 0; }
65 inline bool IsReady() const { return (status & THREADSTATUS_READY) != 0; }
66 inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; }
67 inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; }
68 inline bool IsIdle() const { return idle; }
69
70 ResultVal<bool> WaitSynchronization() override;
71
72 Core::ThreadContext context;
73
74 u32 thread_id;
75
76 u32 status;
77 u32 entry_point;
78 u32 stack_top;
79 u32 stack_size;
80
81 s32 initial_priority;
82 s32 current_priority;
83
84 s32 processor_id;
85
86 WaitType wait_type;
87 Handle wait_handle;
88 VAddr wait_address;
89
90 std::vector<Handle> waiting_threads;
91
92 std::string name;
93
94 /// Whether this thread is intended to never actually be executed, i.e. always idle
95 bool idle = false;
96
97private:
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;
103};
104
51/// Creates a new thread - wrapper for external user 105/// Creates a new thread - wrapper for external user
52Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id, 106Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id,
53 u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE); 107 u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE);
@@ -78,6 +132,9 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address);
78/// Arbitrate all threads currently waiting... 132/// Arbitrate all threads currently waiting...
79void ArbitrateAllThreads(u32 arbiter, u32 address); 133void ArbitrateAllThreads(u32 arbiter, u32 address);
80 134
135/// Gets the current thread
136Thread* GetCurrentThread();
137
81/// Gets the current thread handle 138/// Gets the current thread handle
82Handle GetCurrentThreadHandle(); 139Handle GetCurrentThreadHandle();
83 140