citra-emu
/
citra
Archived
1
0
Fork 0

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() {
const auto& threads = Kernel::GetThreadList();
const auto& threads = Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
std::vector<std::unique_ptr<WaitTreeThread>> item_list;
item_list.reserve(threads.size());
for (std::size_t i = 0; i < threads.size(); ++i) {

View File

@ -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<u32>(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<?xml version=\"1.0\"?>";
buffer += "<threads>";
const auto& threads = Kernel::GetThreadList();
const auto& threads =
Core::System::GetInstance().Kernel().GetThreadManager().GetThreadList();
for (const auto& thread : threads) {
buffer += fmt::format(R"*(<thread id="{:x}" name="Thread {:x}"></thread>)*",
thread->GetThreadId(), thread->GetThreadId());

View File

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

View File

@ -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;

View File

@ -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<SharedPtr<Thread>> thread_list;
u32 ThreadManager::NewThreadId() {
return next_thread_id++;
}
@ -311,7 +308,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
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->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<SharedPtr<Thread>>& GetThreadList() {
const std::vector<SharedPtr<Thread>>& ThreadManager::GetThreadList() {
return thread_list;
}

View File

@ -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<SharedPtr<Thread>>& 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<SharedPtr<Thread>> thread_list;
friend class Thread;
friend class KernelSystem;
};
@ -300,14 +309,4 @@ private:
SharedPtr<Thread> SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority,
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