kernel/Thread: move thread list into the manager

This commit is contained in:
Weiyi Wang 2018-10-23 12:18:35 -04:00
parent 7fc61920cc
commit 20ae37ba4f
6 changed files with 19 additions and 26 deletions

View file

@ -51,7 +51,7 @@ std::size_t WaitTreeItem::Row() const {
} }
std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() { std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() {
const auto& threads = Kernel::GetThreadList(); const auto& threads = Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
std::vector<std::unique_ptr<WaitTreeThread>> item_list; std::vector<std::unique_ptr<WaitTreeThread>> item_list;
item_list.reserve(threads.size()); item_list.reserve(threads.size());
for (std::size_t i = 0; i < threads.size(); ++i) { for (std::size_t i = 0; i < threads.size(); ++i) {

View file

@ -160,7 +160,7 @@ BreakpointMap breakpoints_write;
} // Anonymous namespace } // Anonymous namespace
static Kernel::Thread* FindThreadById(int id) { static Kernel::Thread* FindThreadById(int id) {
const auto& threads = Kernel::GetThreadList(); const auto& threads = Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
for (auto& thread : threads) { for (auto& thread : threads) {
if (thread->GetThreadId() == static_cast<u32>(id)) { if (thread->GetThreadId() == static_cast<u32>(id)) {
return thread.get(); return thread.get();
@ -535,7 +535,8 @@ static void HandleQuery() {
SendReply(target_xml); SendReply(target_xml);
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) { } else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
std::string val = "m"; std::string val = "m";
const auto& threads = Kernel::GetThreadList(); const auto& threads =
Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
for (const auto& thread : threads) { for (const auto& thread : threads) {
val += fmt::format("{:x},", thread->GetThreadId()); val += fmt::format("{:x},", thread->GetThreadId());
} }
@ -547,7 +548,8 @@ static void HandleQuery() {
std::string buffer; std::string buffer;
buffer += "l<?xml version=\"1.0\"?>"; buffer += "l<?xml version=\"1.0\"?>";
buffer += "<threads>"; buffer += "<threads>";
const auto& threads = Kernel::GetThreadList(); const auto& threads =
Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
for (const auto& thread : threads) { for (const auto& thread : threads) {
buffer += fmt::format(R"*(<thread id="{:x}" name="Thread {:x}"></thread>)*", buffer += fmt::format(R"*(<thread id="{:x}" name="Thread {:x}"></thread>)*",
thread->GetThreadId(), thread->GetThreadId()); thread->GetThreadId(), thread->GetThreadId());

View file

@ -27,8 +27,6 @@ KernelSystem::KernelSystem(u32 system_mode) {
/// Shutdown the kernel /// Shutdown the kernel
KernelSystem::~KernelSystem() { KernelSystem::~KernelSystem() {
Kernel::ThreadingShutdown();
Kernel::TimersShutdown(); Kernel::TimersShutdown();
Kernel::MemoryShutdown(); Kernel::MemoryShutdown();
} }

View file

@ -154,7 +154,7 @@ static void ExitProcess() {
current_process->status = ProcessStatus::Exited; current_process->status = ProcessStatus::Exited;
// Stop all the process threads that are currently waiting for objects. // 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) { for (auto& thread : thread_list) {
if (thread->owner_process != current_process) if (thread->owner_process != current_process)
continue; continue;

View file

@ -33,9 +33,6 @@ void Thread::Acquire(Thread* thread) {
ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
} }
// Lists all thread ids that aren't deleted/etc.
static std::vector<SharedPtr<Thread>> thread_list;
u32 ThreadManager::NewThreadId() { u32 ThreadManager::NewThreadId() {
return next_thread_id++; return next_thread_id++;
} }
@ -311,7 +308,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
SharedPtr<Thread> thread(new Thread(*this)); SharedPtr<Thread> thread(new Thread(*this));
thread_list.push_back(thread); thread_manager->thread_list.push_back(thread);
thread_manager->ready_queue.prepare(priority); thread_manager->ready_queue.prepare(priority);
thread->thread_id = thread_manager->NewThreadId(); thread->thread_id = thread_manager->NewThreadId();
@ -464,8 +461,6 @@ VAddr Thread::GetCommandBufferAddress() const {
return GetTLSAddress() + CommandHeaderOffset; return GetTLSAddress() + CommandHeaderOffset;
} }
////////////////////////////////////////////////////////////////////////////////////////////////////
ThreadManager::ThreadManager() { ThreadManager::ThreadManager() {
ThreadWakeupEventType = ThreadWakeupEventType =
CoreTiming::RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) { 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) { for (auto& t : thread_list) {
t->Stop(); t->Stop();
} }
thread_list.clear();
} }
const std::vector<SharedPtr<Thread>>& GetThreadList() { const std::vector<SharedPtr<Thread>>& ThreadManager::GetThreadList() {
return thread_list; return thread_list;
} }

View file

@ -58,6 +58,7 @@ enum class ThreadWakeupReason {
class ThreadManager { class ThreadManager {
public: public:
ThreadManager(); ThreadManager();
~ThreadManager();
/** /**
* Creates a new thread ID * Creates a new thread ID
@ -95,6 +96,11 @@ public:
*/ */
void ExitCurrentThread(); void ExitCurrentThread();
/**
* Get a const reference to the thread list for debug use
*/
const std::vector<SharedPtr<Thread>>& GetThreadList();
private: private:
/** /**
* Switches the CPU's active thread context to that of the specified thread * 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 /// Event type for the thread wake up event
CoreTiming::EventType* ThreadWakeupEventType = nullptr; CoreTiming::EventType* ThreadWakeupEventType = nullptr;
// Lists all threadsthat aren't deleted.
std::vector<SharedPtr<Thread>> thread_list;
friend class Thread; friend class Thread;
friend class KernelSystem; friend class KernelSystem;
}; };
@ -300,14 +309,4 @@ private:
SharedPtr<Thread> SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, SharedPtr<Thread> SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority,
SharedPtr<Process> owner_process); SharedPtr<Process> owner_process);
/**
* Shutdown threading
*/
void ThreadingShutdown();
/**
* Get a const reference to the thread list for debug use
*/
const std::vector<SharedPtr<Thread>>& GetThreadList();
} // namespace Kernel } // namespace Kernel