diff options
| author | 2014-12-28 21:11:55 -0500 | |
|---|---|---|
| committer | 2014-12-28 21:11:55 -0500 | |
| commit | 77363d9590ed544cf714f26c575e98b7858e18e1 (patch) | |
| tree | a48225a3b62bb3d72d94289b6e34326cbed4f5cc /src/core/hle/kernel/thread.cpp | |
| parent | Merge pull request #357 from bunnei/dyncom-pkhbt-pkhtb (diff) | |
| parent | Kernel: New handle manager (diff) | |
| download | yuzu-77363d9590ed544cf714f26c575e98b7858e18e1.tar.gz yuzu-77363d9590ed544cf714f26c575e98b7858e18e1.tar.xz yuzu-77363d9590ed544cf714f26c575e98b7858e18e1.zip | |
Merge pull request #331 from yuriks/handle-reform
New Handle manager
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index c6a8dc7b9..872df2d14 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -26,8 +26,8 @@ public: | |||
| 26 | std::string GetName() const override { return name; } | 26 | std::string GetName() const override { return name; } |
| 27 | std::string GetTypeName() const override { return "Thread"; } | 27 | std::string GetTypeName() const override { return "Thread"; } |
| 28 | 28 | ||
| 29 | static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Thread; } | 29 | static const HandleType HANDLE_TYPE = HandleType::Thread; |
| 30 | Kernel::HandleType GetHandleType() const override { return Kernel::HandleType::Thread; } | 30 | HandleType GetHandleType() const override { return HANDLE_TYPE; } |
| 31 | 31 | ||
| 32 | inline bool IsRunning() const { return (status & THREADSTATUS_RUNNING) != 0; } | 32 | inline bool IsRunning() const { return (status & THREADSTATUS_RUNNING) != 0; } |
| 33 | inline bool IsStopped() const { return (status & THREADSTATUS_DORMANT) != 0; } | 33 | inline bool IsStopped() const { return (status & THREADSTATUS_DORMANT) != 0; } |
| @@ -164,7 +164,7 @@ static bool CheckWaitType(const Thread* thread, WaitType type, Handle wait_handl | |||
| 164 | 164 | ||
| 165 | /// Stops the current thread | 165 | /// Stops the current thread |
| 166 | ResultCode StopThread(Handle handle, const char* reason) { | 166 | ResultCode StopThread(Handle handle, const char* reason) { |
| 167 | Thread* thread = g_object_pool.Get<Thread>(handle); | 167 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 168 | if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); | 168 | if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); |
| 169 | 169 | ||
| 170 | // Release all the mutexes that this thread holds | 170 | // Release all the mutexes that this thread holds |
| @@ -173,7 +173,7 @@ ResultCode StopThread(Handle handle, const char* reason) { | |||
| 173 | ChangeReadyState(thread, false); | 173 | ChangeReadyState(thread, false); |
| 174 | thread->status = THREADSTATUS_DORMANT; | 174 | thread->status = THREADSTATUS_DORMANT; |
| 175 | for (Handle waiting_handle : thread->waiting_threads) { | 175 | for (Handle waiting_handle : thread->waiting_threads) { |
| 176 | Thread* waiting_thread = g_object_pool.Get<Thread>(waiting_handle); | 176 | Thread* waiting_thread = g_handle_table.Get<Thread>(waiting_handle); |
| 177 | 177 | ||
| 178 | if (CheckWaitType(waiting_thread, WAITTYPE_THREADEND, handle)) | 178 | if (CheckWaitType(waiting_thread, WAITTYPE_THREADEND, handle)) |
| 179 | ResumeThreadFromWait(waiting_handle); | 179 | ResumeThreadFromWait(waiting_handle); |
| @@ -210,7 +210,7 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address) { | |||
| 210 | 210 | ||
| 211 | // Iterate through threads, find highest priority thread that is waiting to be arbitrated... | 211 | // Iterate through threads, find highest priority thread that is waiting to be arbitrated... |
| 212 | for (Handle handle : thread_queue) { | 212 | for (Handle handle : thread_queue) { |
| 213 | Thread* thread = g_object_pool.Get<Thread>(handle); | 213 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 214 | 214 | ||
| 215 | if (!CheckWaitType(thread, WAITTYPE_ARB, arbiter, address)) | 215 | if (!CheckWaitType(thread, WAITTYPE_ARB, arbiter, address)) |
| 216 | continue; | 216 | continue; |
| @@ -235,7 +235,7 @@ void ArbitrateAllThreads(u32 arbiter, u32 address) { | |||
| 235 | 235 | ||
| 236 | // Iterate through threads, find highest priority thread that is waiting to be arbitrated... | 236 | // Iterate through threads, find highest priority thread that is waiting to be arbitrated... |
| 237 | for (Handle handle : thread_queue) { | 237 | for (Handle handle : thread_queue) { |
| 238 | Thread* thread = g_object_pool.Get<Thread>(handle); | 238 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 239 | 239 | ||
| 240 | if (CheckWaitType(thread, WAITTYPE_ARB, arbiter, address)) | 240 | if (CheckWaitType(thread, WAITTYPE_ARB, arbiter, address)) |
| 241 | ResumeThreadFromWait(handle); | 241 | ResumeThreadFromWait(handle); |
| @@ -288,7 +288,7 @@ Thread* NextThread() { | |||
| 288 | if (next == 0) { | 288 | if (next == 0) { |
| 289 | return nullptr; | 289 | return nullptr; |
| 290 | } | 290 | } |
| 291 | return Kernel::g_object_pool.Get<Thread>(next); | 291 | return Kernel::g_handle_table.Get<Thread>(next); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle) { | 294 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle) { |
| @@ -305,7 +305,7 @@ void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_addres | |||
| 305 | 305 | ||
| 306 | /// Resumes a thread from waiting by marking it as "ready" | 306 | /// Resumes a thread from waiting by marking it as "ready" |
| 307 | void ResumeThreadFromWait(Handle handle) { | 307 | void ResumeThreadFromWait(Handle handle) { |
| 308 | Thread* thread = Kernel::g_object_pool.Get<Thread>(handle); | 308 | Thread* thread = Kernel::g_handle_table.Get<Thread>(handle); |
| 309 | if (thread) { | 309 | if (thread) { |
| 310 | thread->status &= ~THREADSTATUS_WAIT; | 310 | thread->status &= ~THREADSTATUS_WAIT; |
| 311 | thread->wait_handle = 0; | 311 | thread->wait_handle = 0; |
| @@ -341,7 +341,8 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio | |||
| 341 | 341 | ||
| 342 | Thread* thread = new Thread; | 342 | Thread* thread = new Thread; |
| 343 | 343 | ||
| 344 | handle = Kernel::g_object_pool.Create(thread); | 344 | // TOOD(yuriks): Fix error reporting |
| 345 | handle = Kernel::g_handle_table.Create(thread).ValueOr(INVALID_HANDLE); | ||
| 345 | 346 | ||
| 346 | thread_queue.push_back(handle); | 347 | thread_queue.push_back(handle); |
| 347 | thread_ready_queue.prepare(priority); | 348 | thread_ready_queue.prepare(priority); |
| @@ -398,7 +399,7 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3 | |||
| 398 | 399 | ||
| 399 | /// Get the priority of the thread specified by handle | 400 | /// Get the priority of the thread specified by handle |
| 400 | ResultVal<u32> GetThreadPriority(const Handle handle) { | 401 | ResultVal<u32> GetThreadPriority(const Handle handle) { |
| 401 | Thread* thread = g_object_pool.Get<Thread>(handle); | 402 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 402 | if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); | 403 | if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); |
| 403 | 404 | ||
| 404 | return MakeResult<u32>(thread->current_priority); | 405 | return MakeResult<u32>(thread->current_priority); |
| @@ -410,7 +411,7 @@ ResultCode SetThreadPriority(Handle handle, s32 priority) { | |||
| 410 | if (!handle) { | 411 | if (!handle) { |
| 411 | thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior? | 412 | thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior? |
| 412 | } else { | 413 | } else { |
| 413 | thread = g_object_pool.Get<Thread>(handle); | 414 | thread = g_handle_table.Get<Thread>(handle); |
| 414 | if (thread == nullptr) { | 415 | if (thread == nullptr) { |
| 415 | return InvalidHandle(ErrorModule::Kernel); | 416 | return InvalidHandle(ErrorModule::Kernel); |
| 416 | } | 417 | } |
| @@ -481,7 +482,7 @@ void Reschedule() { | |||
| 481 | LOG_TRACE(Kernel, "cannot context switch from 0x%08X, no higher priority thread!", prev->GetHandle()); | 482 | LOG_TRACE(Kernel, "cannot context switch from 0x%08X, no higher priority thread!", prev->GetHandle()); |
| 482 | 483 | ||
| 483 | for (Handle handle : thread_queue) { | 484 | for (Handle handle : thread_queue) { |
| 484 | Thread* thread = g_object_pool.Get<Thread>(handle); | 485 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 485 | LOG_TRACE(Kernel, "\thandle=0x%08X prio=0x%02X, status=0x%08X wait_type=0x%08X wait_handle=0x%08X", | 486 | LOG_TRACE(Kernel, "\thandle=0x%08X prio=0x%02X, status=0x%08X wait_type=0x%08X wait_handle=0x%08X", |
| 486 | thread->GetHandle(), thread->current_priority, thread->status, thread->wait_type, thread->wait_handle); | 487 | thread->GetHandle(), thread->current_priority, thread->status, thread->wait_type, thread->wait_handle); |
| 487 | } | 488 | } |
| @@ -497,7 +498,7 @@ void Reschedule() { | |||
| 497 | } | 498 | } |
| 498 | 499 | ||
| 499 | ResultCode GetThreadId(u32* thread_id, Handle handle) { | 500 | ResultCode GetThreadId(u32* thread_id, Handle handle) { |
| 500 | Thread* thread = g_object_pool.Get<Thread>(handle); | 501 | Thread* thread = g_handle_table.Get<Thread>(handle); |
| 501 | if (thread == nullptr) | 502 | if (thread == nullptr) |
| 502 | return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS, | 503 | return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS, |
| 503 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | 504 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); |