From addc0bf0379e075786048921bede6e089552a6db Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 4 Apr 2021 00:56:09 -0700 Subject: hle: kernel: Migrate KEvent to KAutoObject. --- src/core/hle/kernel/k_event.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/core/hle/kernel/k_event.cpp') diff --git a/src/core/hle/kernel/k_event.cpp b/src/core/hle/kernel/k_event.cpp index bb2fa4ad5..bc4a79cc8 100644 --- a/src/core/hle/kernel/k_event.cpp +++ b/src/core/hle/kernel/k_event.cpp @@ -4,29 +4,53 @@ #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" +#include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_writable_event.h" +#include "core/hle/kernel/process.h" namespace Kernel { -KEvent::KEvent(KernelCore& kernel, std::string&& name) : Object{kernel, std::move(name)} {} +KEvent::KEvent(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {} KEvent::~KEvent() = default; -std::shared_ptr KEvent::Create(KernelCore& kernel, std::string&& name) { - return std::make_shared(kernel, std::move(name)); -} +void KEvent::Initialize(std::string&& name_) { + // Increment reference count. + // Because reference count is one on creation, this will result + // in a reference count of two. Thus, when both readable and + // writable events are closed this object will be destroyed. + Open(); -void KEvent::Initialize() { // Create our sub events. - readable_event = std::make_shared(kernel, GetName() + ":Readable"); - writable_event = std::make_shared(kernel, GetName() + ":Writable"); + readable_event = std::make_shared(kernel, name_ + ":Readable"); + writable_event = std::make_shared(kernel, name_ + ":Writable"); // Initialize our sub sessions. readable_event->Initialize(this); writable_event->Initialize(this); + // Set our owner process. + owner = kernel.CurrentProcess(); + if (owner) { + owner->Open(); + } + // Mark initialized. + name = std::move(name_); initialized = true; } +void KEvent::Finalize() { + KAutoObjectWithSlabHeapAndContainer::Finalize(); +} + +void KEvent::PostDestroy(uintptr_t arg) { + // Release the event count resource the owner process holds. + Process* owner = reinterpret_cast(arg); + if (owner) { + owner->GetResourceLimit()->Release(LimitableResource::Events, 1); + owner->Close(); + } +} + } // namespace Kernel -- cgit v1.2.3 From b6156e735cd78d4b7863491ae6bdc63e44404b73 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 9 Apr 2021 22:10:14 -0700 Subject: hle: kernel: Move slab heap management to KernelCore. --- src/core/hle/kernel/k_event.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/kernel/k_event.cpp') diff --git a/src/core/hle/kernel/k_event.cpp b/src/core/hle/kernel/k_event.cpp index bc4a79cc8..4020e5325 100644 --- a/src/core/hle/kernel/k_event.cpp +++ b/src/core/hle/kernel/k_event.cpp @@ -21,6 +21,10 @@ void KEvent::Initialize(std::string&& name_) { // writable events are closed this object will be destroyed. Open(); + //// Create our sub events. + //KAutoObject::Create(readable_event.get()); + //KAutoObject::Create(writable_event.get()); + // Create our sub events. readable_event = std::make_shared(kernel, name_ + ":Readable"); writable_event = std::make_shared(kernel, name_ + ":Writable"); -- cgit v1.2.3 From 2e8d6fe9a0c07538397682e1cb25992bfd15676d Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 10 Apr 2021 02:34:26 -0700 Subject: hle: kernel: Migrate KReadableEvent and KWritableEvent to KAutoObject. --- src/core/hle/kernel/k_event.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/core/hle/kernel/k_event.cpp') diff --git a/src/core/hle/kernel/k_event.cpp b/src/core/hle/kernel/k_event.cpp index 4020e5325..fdec0c36f 100644 --- a/src/core/hle/kernel/k_event.cpp +++ b/src/core/hle/kernel/k_event.cpp @@ -3,14 +3,13 @@ // Refer to the license.txt file included. #include "core/hle/kernel/k_event.h" -#include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_resource_limit.h" -#include "core/hle/kernel/k_writable_event.h" #include "core/hle/kernel/process.h" namespace Kernel { -KEvent::KEvent(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {} +KEvent::KEvent(KernelCore& kernel) + : KAutoObjectWithSlabHeapAndContainer{kernel}, readable_event{kernel}, writable_event{kernel} {} KEvent::~KEvent() = default; @@ -21,17 +20,13 @@ void KEvent::Initialize(std::string&& name_) { // writable events are closed this object will be destroyed. Open(); - //// Create our sub events. - //KAutoObject::Create(readable_event.get()); - //KAutoObject::Create(writable_event.get()); - // Create our sub events. - readable_event = std::make_shared(kernel, name_ + ":Readable"); - writable_event = std::make_shared(kernel, name_ + ":Writable"); + KAutoObject::Create(std::addressof(readable_event)); + KAutoObject::Create(std::addressof(writable_event)); // Initialize our sub sessions. - readable_event->Initialize(this); - writable_event->Initialize(this); + readable_event.Initialize(this, name_ + ":Readable"); + writable_event.Initialize(this, name_ + ":Writable"); // Set our owner process. owner = kernel.CurrentProcess(); -- cgit v1.2.3 From 2a7eff57a8048933a89c1a8f8d6dced7b5d604f2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 23 Apr 2021 22:04:28 -0700 Subject: hle: kernel: Rename Process to KProcess. --- src/core/hle/kernel/k_event.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/kernel/k_event.cpp') diff --git a/src/core/hle/kernel/k_event.cpp b/src/core/hle/kernel/k_event.cpp index fdec0c36f..986355b78 100644 --- a/src/core/hle/kernel/k_event.cpp +++ b/src/core/hle/kernel/k_event.cpp @@ -3,8 +3,8 @@ // Refer to the license.txt file included. #include "core/hle/kernel/k_event.h" +#include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_resource_limit.h" -#include "core/hle/kernel/process.h" namespace Kernel { @@ -45,7 +45,7 @@ void KEvent::Finalize() { void KEvent::PostDestroy(uintptr_t arg) { // Release the event count resource the owner process holds. - Process* owner = reinterpret_cast(arg); + KProcess* owner = reinterpret_cast(arg); if (owner) { owner->GetResourceLimit()->Release(LimitableResource::Events, 1); owner->Close(); -- cgit v1.2.3