aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv <subv2112@gmail.com>2014-12-03 23:22:06 -0500
committerGravatar Subv <subv2112@gmail.com>2014-12-04 00:25:35 -0500
commit029ff9f1fd013ec46f3d61510c5f95f05bca698e (patch)
tree17177b27e64fa60c0c1847ba02e8ae187f0eebad /src
parent63b1453dd8f0f579929fe7341f559b916cebcc2b (diff)
SVC: Implemented GetThreadId.
For now threads are using their Handle value as their Id, it should not really cause any problems because Handle values are unique in Citra, but it should be changed. I left a ToDo there because this is not correct behavior as per hardware.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/thread.cpp16
-rw-r--r--src/core/hle/kernel/thread.h3
-rw-r--r--src/core/hle/svc.cpp9
3 files changed, 24 insertions, 4 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index f5979590..6da23882 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -49,6 +49,8 @@ public:
ThreadContext context;
+ u32 thread_id;
+
u32 status;
u32 entry_point;
u32 stack_top;
@@ -325,6 +327,9 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio
thread_queue.push_back(handle);
thread_ready_queue.prepare(priority);
+ // TODO(Subv): Assign valid ids to each thread, they are much lower than handle values
+ // they appear to begin at 276 and continue from there
+ thread->thread_id = handle;
thread->status = THREADSTATUS_DORMANT;
thread->entry_point = entry_point;
thread->stack_top = stack_top;
@@ -465,6 +470,17 @@ void Reschedule() {
}
}
+ResultCode GetThreadId(u32* thread_id, Handle handle) {
+ Thread* thread = g_object_pool.Get<Thread>(handle);
+ if (thread == nullptr)
+ return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS,
+ ErrorSummary::WrongArgument, ErrorLevel::Permanent);
+
+ *thread_id = thread->thread_id;
+
+ return RESULT_SUCCESS;
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
void ThreadingInit() {
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index ce63a70d..e87867ac 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -58,6 +58,9 @@ void Reschedule();
/// Stops the current thread
ResultCode StopThread(Handle thread, const char* reason);
+// Retrieves the thread id of the specified thread handle
+ResultCode GetThreadId(u32* thread_id, Handle handle);
+
/// Resumes a thread from waiting by marking it as "ready"
void ResumeThreadFromWait(Handle handle);
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 43a3cbe0..a5805ed0 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -281,10 +281,11 @@ static Result ReleaseMutex(Handle handle) {
return res.raw;
}
-/// Get current thread ID
-static Result GetThreadId(u32* thread_id, Handle thread) {
- ERROR_LOG(SVC, "(UNIMPLEMENTED) called thread=0x%08X", thread);
- return 0;
+/// Get the ID for the specified thread.
+static Result GetThreadId(u32* thread_id, Handle handle) {
+ DEBUG_LOG(SVC, "called thread=0x%08X", handle);
+ ResultCode result = Kernel::GetThreadId(thread_id, handle);
+ return result.raw;
}
/// Query memory