Replace g_kernel with Core::Global etc.

This commit is contained in:
Hamish Milne 2019-12-25 18:51:56 +00:00 committed by zhupengfei
parent e707685c2a
commit 3e752002c4
15 changed files with 43 additions and 17 deletions

2
TODO
View File

@ -26,7 +26,7 @@
✔ Shader @done(19-08-13 16:03)
☐ HLE @started(19-08-13 16:43)
☐ Kernel @started(19-08-13 16:43)
Most of these require adding g_kernel
Most of these require adding Core::Global
✔ Address arbiter @done(19-08-13 16:40)
✔ Client port @done(19-08-13 16:40)
✔ Client session @done(19-08-13 16:40)

View File

@ -25,6 +25,7 @@
#endif
#include "core/custom_tex_cache.h"
#include "core/gdbstub/gdbstub.h"
#include "core/global.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
@ -46,6 +47,12 @@ namespace Core {
/*static*/ System System::s_instance;
template <>
Core::System& Global() { return System::GetInstance(); }
template <>
Kernel::KernelSystem& Global() { return System::GetInstance().Kernel(); }
System::ResultStatus System::RunLoop(bool tight_loop) {
status = ResultStatus::Success;
if (!cpu_core) {
@ -204,7 +211,6 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo
kernel = std::make_unique<Kernel::KernelSystem>(*memory, *timing,
[this] { PrepareReschedule(); }, system_mode);
Kernel::g_kernel = kernel.get();
if (Settings::values.use_cpu_jit) {
#ifdef ARCHITECTURE_x86_64
@ -368,7 +374,6 @@ void System::Shutdown() {
service_manager.reset();
dsp_core.reset();
cpu_core.reset();
Kernel::g_kernel = nullptr;
kernel.reset();
timing.reset();
app_loader.reset();

6
src/core/global.h Normal file
View File

@ -0,0 +1,6 @@
namespace Core {
template <class T>
T& Global();
} // namespace Core

View File

@ -11,6 +11,7 @@
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/thread.h"
#include "core/memory.h"
#include "core/global.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Kernel namespace
@ -68,7 +69,7 @@ std::shared_ptr<Thread> AddressArbiter::ResumeHighestPriorityThread(VAddr addres
return thread;
}
AddressArbiter::AddressArbiter() : kernel(*g_kernel) {}
AddressArbiter::AddressArbiter() : kernel(Core::Global<KernelSystem>()) {}
AddressArbiter::~AddressArbiter() {}
std::shared_ptr<AddressArbiter> KernelSystem::CreateAddressArbiter(std::string name) {

View File

@ -11,6 +11,7 @@
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h"
#include "core/global.h"
SERIALIZE_EXPORT_IMPL(Kernel::ClientPort)
@ -26,7 +27,7 @@ ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
active_sessions++;
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
auto [server, client] = g_kernel->CreateSessionPair(server_port->GetName(), SharedFrom(this));
auto [server, client] = Core::Global<KernelSystem>().CreateSessionPair(server_port->GetName(), SharedFrom(this));
if (server_port->hle_handler)
server_port->hle_handler->ClientConnected(server);

View File

@ -18,8 +18,6 @@
namespace Kernel {
KernelSystem* g_kernel;
/// Initialize the kernel
KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing,
std::function<void()> prepare_reschedule_callback, u32 system_mode)

View File

@ -292,6 +292,4 @@ private:
void serialize(Archive& ar, const unsigned int file_version);
};
extern KernelSystem* g_kernel;
} // namespace Kernel

View File

@ -12,6 +12,7 @@
#include "core/hle/kernel/mutex.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/thread.h"
#include "core/global.h"
SERIALIZE_EXPORT_IMPL(Kernel::Mutex)
@ -26,7 +27,7 @@ void ReleaseThreadMutexes(Thread* thread) {
thread->held_mutexes.clear();
}
Mutex::Mutex() : kernel(*g_kernel) {}
Mutex::Mutex() : kernel(Core::Global<KernelSystem>()) {}
Mutex::~Mutex() {}
std::shared_ptr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {

View File

@ -18,6 +18,7 @@
#include "core/hle/kernel/thread.h"
#include "core/hle/kernel/vm_manager.h"
#include "core/memory.h"
#include "core/global.h"
namespace Kernel {
@ -427,7 +428,11 @@ ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission pe
return RESULT_SUCCESS;
}
Kernel::Process::Process() : kernel(*g_kernel), handle_table(*g_kernel), vm_manager(g_kernel->memory)
Kernel::Process::Process() : Kernel::Process::Process(Core::Global<KernelSystem>())
{
}
Kernel::Process::Process(KernelSystem& kernel) : kernel(kernel), handle_table(kernel), vm_manager(kernel.memory)
{
kernel.memory.RegisterPageTable(&vm_manager.page_table);
}

View File

@ -143,7 +143,8 @@ private:
class Process final : public Object {
public:
explicit Process();
Process();
explicit Process(KernelSystem& kernel);
~Process() override;
std::string GetTypeName() const override {

View File

@ -10,12 +10,13 @@
#include "core/hle/kernel/server_session.h"
#include "core/hle/kernel/session.h"
#include "core/hle/kernel/thread.h"
#include "core/global.h"
SERIALIZE_EXPORT_IMPL(Kernel::ServerSession)
namespace Kernel {
ServerSession::ServerSession() : kernel(*g_kernel) {}
ServerSession::ServerSession() : kernel(Core::Global<KernelSystem>()) {}
ServerSession::~ServerSession() {
// This destructor will be called automatically when the last ServerSession handle is closed by
// the emulated application.

View File

@ -24,6 +24,7 @@
#include "core/hle/kernel/thread.h"
#include "core/hle/result.h"
#include "core/memory.h"
#include "core/global.h"
SERIALIZE_EXPORT_IMPL(Kernel::Thread)
@ -66,8 +67,8 @@ u32 ThreadManager::NewThreadId() {
}
Thread::Thread()
: context(g_kernel->GetThreadManager().NewContext()),
thread_manager(g_kernel->GetThreadManager()) {}
: context(Core::Global<KernelSystem>().GetThreadManager().NewContext()),
thread_manager(Core::Global<KernelSystem>().GetThreadManager()) {}
Thread::~Thread() {}
Thread* ThreadManager::GetCurrentThread() const {

View File

@ -11,10 +11,11 @@
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/thread.h"
#include "core/hle/kernel/timer.h"
#include "core/global.h"
namespace Kernel {
Timer::Timer() : kernel(*g_kernel), timer_manager(g_kernel->GetTimerManager()) {}
Timer::Timer() : kernel(Core::Global<KernelSystem>()), timer_manager(Core::Global<KernelSystem>().GetTimerManager()) {}
Timer::~Timer() {
Cancel();
timer_manager.timer_callback_table.erase(callback_id);

View File

@ -18,6 +18,7 @@
#include "core/hle/kernel/mutex.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
#include "core/global.h"
namespace Core {
class System;
@ -601,6 +602,6 @@ namespace boost::serialization {
template <class Archive>
inline void load_construct_data(Archive& ar, Service::AM::Module* t, const unsigned int)
{
::new(t)Service::AM::Module(*Kernel::g_kernel);
::new(t)Service::AM::Module(Core::Global<Kernel::KernelSystem>());
}
}

View File

@ -8,6 +8,12 @@
#include "video_core/pica_state.h"
#include "video_core/renderer_base.h"
#include "video_core/video_core.h"
#include "core/global.h"
namespace Core {
template <>
Pica::State& Global() { return Pica::g_state; }
}
namespace Pica {