kernel/thread: add ThreadManager

This commit is contained in:
Weiyi Wang 2018-10-23 09:57:59 -04:00
parent f3ee5feb02
commit 34f1fe088c
4 changed files with 24 additions and 1 deletions

View file

@ -21,6 +21,7 @@ KernelSystem::KernelSystem(u32 system_mode) {
Kernel::MemoryInit(system_mode);
resource_limits = std::make_unique<ResourceLimitList>(*this);
thread_manager = std::make_unique<ThreadManager>();
Kernel::ThreadingInit();
Kernel::TimersInit();
}
@ -53,4 +54,12 @@ void KernelSystem::SetCurrentProcess(SharedPtr<Process> process) {
current_process = std::move(process);
}
ThreadManager& KernelSystem::GetThreadManager() {
return *thread_manager;
}
const ThreadManager& KernelSystem::GetThreadManager() const {
return *thread_manager;
}
} // namespace Kernel

View file

@ -28,6 +28,7 @@ class ClientSession;
class ServerSession;
class ResourceLimitList;
class SharedMemory;
class ThreadManager;
enum class ResetType {
OneShot,
@ -187,6 +188,9 @@ public:
SharedPtr<Process> GetCurrentProcess() const;
void SetCurrentProcess(SharedPtr<Process> process);
ThreadManager& GetThreadManager();
const ThreadManager& GetThreadManager() const;
private:
std::unique_ptr<ResourceLimitList> resource_limits;
std::atomic<u32> next_object_id{0};
@ -199,6 +203,8 @@ private:
std::vector<SharedPtr<Process>> process_list;
SharedPtr<Process> current_process;
std::unique_ptr<ThreadManager> thread_manager;
};
} // namespace Kernel

View file

@ -59,7 +59,9 @@ inline static u32 const NewThreadId() {
return next_thread_id++;
}
Thread::Thread(KernelSystem& kernel) : WaitObject(kernel), context(Core::CPU().NewContext()) {}
Thread::Thread(KernelSystem& kernel)
: WaitObject(kernel), context(Core::CPU().NewContext()),
thread_manager(kernel.GetThreadManager()) {}
Thread::~Thread() {}
Thread* GetCurrentThread() {

View file

@ -53,6 +53,10 @@ enum class ThreadWakeupReason {
Timeout // The thread was woken up due to a wait timeout.
};
class ThreadManager {
public:
};
class Thread final : public WaitObject {
public:
std::string GetName() const override {
@ -210,6 +214,8 @@ private:
explicit Thread(KernelSystem&);
~Thread() override;
ThreadManager& thread_manager;
friend class KernelSystem;
};