From 20ae37ba4f53bf44323d9812c3187174d4a7386a Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Tue, 23 Oct 2018 12:18:35 -0400 Subject: [PATCH] kernel/Thread: move thread list into the manager --- src/citra_qt/debugger/wait_tree.cpp | 2 +- src/core/gdbstub/gdbstub.cpp | 8 +++++--- src/core/hle/kernel/kernel.cpp | 2 -- src/core/hle/kernel/svc.cpp | 2 +- src/core/hle/kernel/thread.cpp | 12 +++--------- src/core/hle/kernel/thread.h | 19 +++++++++---------- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/citra_qt/debugger/wait_tree.cpp b/src/citra_qt/debugger/wait_tree.cpp index d006128e5..0758cc792 100644 --- a/src/citra_qt/debugger/wait_tree.cpp +++ b/src/citra_qt/debugger/wait_tree.cpp @@ -51,7 +51,7 @@ std::size_t WaitTreeItem::Row() const { } std::vector> WaitTreeItem::MakeThreadItemList() { - const auto& threads = Kernel::GetThreadList(); + const auto& threads = Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList(); std::vector> item_list; item_list.reserve(threads.size()); for (std::size_t i = 0; i < threads.size(); ++i) { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index f95b3c66e..1296b71b4 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -160,7 +160,7 @@ BreakpointMap breakpoints_write; } // Anonymous namespace static Kernel::Thread* FindThreadById(int id) { - const auto& threads = Kernel::GetThreadList(); + const auto& threads = Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList(); for (auto& thread : threads) { if (thread->GetThreadId() == static_cast(id)) { return thread.get(); @@ -535,7 +535,8 @@ static void HandleQuery() { SendReply(target_xml); } else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) { std::string val = "m"; - const auto& threads = Kernel::GetThreadList(); + const auto& threads = + Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList(); for (const auto& thread : threads) { val += fmt::format("{:x},", thread->GetThreadId()); } @@ -547,7 +548,8 @@ static void HandleQuery() { std::string buffer; buffer += "l"; buffer += ""; - const auto& threads = Kernel::GetThreadList(); + const auto& threads = + Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList(); for (const auto& thread : threads) { buffer += fmt::format(R"*()*", thread->GetThreadId(), thread->GetThreadId()); diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index ca68e036a..1c324e247 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -27,8 +27,6 @@ KernelSystem::KernelSystem(u32 system_mode) { /// Shutdown the kernel KernelSystem::~KernelSystem() { - Kernel::ThreadingShutdown(); - Kernel::TimersShutdown(); Kernel::MemoryShutdown(); } diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 840a36ca7..07079fc4d 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -154,7 +154,7 @@ static void ExitProcess() { current_process->status = ProcessStatus::Exited; // Stop all the process threads that are currently waiting for objects. - auto& thread_list = GetThreadList(); + auto& thread_list = kernel.GetThreadManager().GetThreadList(); for (auto& thread : thread_list) { if (thread->owner_process != current_process) continue; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index ce035e5a6..236e1d7b0 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -33,9 +33,6 @@ void Thread::Acquire(Thread* thread) { ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); } -// Lists all thread ids that aren't deleted/etc. -static std::vector> thread_list; - u32 ThreadManager::NewThreadId() { return next_thread_id++; } @@ -311,7 +308,7 @@ ResultVal> KernelSystem::CreateThread(std::string name, VAddr SharedPtr thread(new Thread(*this)); - thread_list.push_back(thread); + thread_manager->thread_list.push_back(thread); thread_manager->ready_queue.prepare(priority); thread->thread_id = thread_manager->NewThreadId(); @@ -464,8 +461,6 @@ VAddr Thread::GetCommandBufferAddress() const { return GetTLSAddress() + CommandHeaderOffset; } -//////////////////////////////////////////////////////////////////////////////////////////////////// - ThreadManager::ThreadManager() { ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) { @@ -473,14 +468,13 @@ ThreadManager::ThreadManager() { }); } -void ThreadingShutdown() { +ThreadManager::~ThreadManager() { for (auto& t : thread_list) { t->Stop(); } - thread_list.clear(); } -const std::vector>& GetThreadList() { +const std::vector>& ThreadManager::GetThreadList() { return thread_list; } diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index cc229dc18..06a7c5f4f 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -58,6 +58,7 @@ enum class ThreadWakeupReason { class ThreadManager { public: ThreadManager(); + ~ThreadManager(); /** * Creates a new thread ID @@ -95,6 +96,11 @@ public: */ void ExitCurrentThread(); + /** + * Get a const reference to the thread list for debug use + */ + const std::vector>& GetThreadList(); + private: /** * Switches the CPU's active thread context to that of the specified thread @@ -123,6 +129,9 @@ private: /// Event type for the thread wake up event CoreTiming::EventType* ThreadWakeupEventType = nullptr; + // Lists all threadsthat aren't deleted. + std::vector> thread_list; + friend class Thread; friend class KernelSystem; }; @@ -300,14 +309,4 @@ private: SharedPtr SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, SharedPtr owner_process); -/** - * Shutdown threading - */ -void ThreadingShutdown(); - -/** - * Get a const reference to the thread list for debug use - */ -const std::vector>& GetThreadList(); - } // namespace Kernel