From 8ad41775ccae67e54e9f03cbe054d7562b1c66ce Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 29 Dec 2014 10:55:30 -0200 Subject: Kernel: Start using boost::intrusive_ptr for lifetime management --- src/core/hle/kernel/kernel.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/core/hle/kernel/kernel.cpp') diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 7d40dcbee..d3684896f 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -14,7 +14,7 @@ namespace Kernel { -Thread* g_main_thread = nullptr; +SharedPtr g_main_thread = nullptr; HandleTable g_handle_table; u64 g_program_id = 0; @@ -23,7 +23,7 @@ HandleTable::HandleTable() { Clear(); } -ResultVal HandleTable::Create(Object* obj) { +ResultVal HandleTable::Create(SharedPtr obj) { _dbg_assert_(Kernel, obj != nullptr); u16 slot = next_free_slot; @@ -39,23 +39,23 @@ ResultVal HandleTable::Create(Object* obj) { // CTR-OS doesn't use generation 0, so skip straight to 1. if (next_generation >= (1 << 15)) next_generation = 1; - generations[slot] = generation; - intrusive_ptr_add_ref(obj); - objects[slot] = obj; - Handle handle = generation | (slot << 15); if (obj->handle == INVALID_HANDLE) obj->handle = handle; + + generations[slot] = generation; + objects[slot] = std::move(obj); + return MakeResult(handle); } ResultVal HandleTable::Duplicate(Handle handle) { - Object* object = GetGeneric(handle); + SharedPtr object = GetGeneric(handle); if (object == nullptr) { LOG_ERROR(Kernel, "Tried to duplicate invalid handle: %08X", handle); return ERR_INVALID_HANDLE; } - return Create(object); + return Create(std::move(object)); } ResultCode HandleTable::Close(Handle handle) { @@ -65,7 +65,6 @@ ResultCode HandleTable::Close(Handle handle) { size_t slot = GetSlot(handle); u16 generation = GetGeneration(handle); - intrusive_ptr_release(objects[slot]); objects[slot] = nullptr; generations[generation] = next_free_slot; @@ -80,7 +79,7 @@ bool HandleTable::IsValid(Handle handle) const { return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation; } -Object* HandleTable::GetGeneric(Handle handle) const { +SharedPtr HandleTable::GetGeneric(Handle handle) const { if (handle == CurrentThread) { return GetCurrentThread(); } else if (handle == CurrentProcess) { @@ -97,8 +96,6 @@ Object* HandleTable::GetGeneric(Handle handle) const { void HandleTable::Clear() { for (size_t i = 0; i < MAX_COUNT; ++i) { generations[i] = i + 1; - if (objects[i] != nullptr) - intrusive_ptr_release(objects[i]); objects[i] = nullptr; } next_free_slot = 0; @@ -126,7 +123,7 @@ bool LoadExec(u32 entry_point) { Core::g_app_core->SetPC(entry_point); // 0x30 is the typical main thread priority I've seen used so far - g_main_thread = Kernel::SetupMainThread(0x30); + g_main_thread = Kernel::SetupMainThread(0x30, Kernel::DEFAULT_STACK_SIZE); // Setup the idle thread Kernel::SetupIdleThread(); -- cgit v1.2.3