summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_event.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/k_event.cpp')
-rw-r--r--src/core/hle/kernel/k_event.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/core/hle/kernel/k_event.cpp b/src/core/hle/kernel/k_event.cpp
index bb2fa4ad5..986355b78 100644
--- a/src/core/hle/kernel/k_event.cpp
+++ b/src/core/hle/kernel/k_event.cpp
@@ -3,30 +3,53 @@
// 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_writable_event.h"
+#include "core/hle/kernel/k_process.h"
+#include "core/hle/kernel/k_resource_limit.h"
namespace Kernel {
-KEvent::KEvent(KernelCore& kernel, std::string&& name) : Object{kernel, std::move(name)} {}
+KEvent::KEvent(KernelCore& kernel)
+ : KAutoObjectWithSlabHeapAndContainer{kernel}, readable_event{kernel}, writable_event{kernel} {}
KEvent::~KEvent() = default;
-std::shared_ptr<KEvent> KEvent::Create(KernelCore& kernel, std::string&& name) {
- return std::make_shared<KEvent>(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<KReadableEvent>(kernel, GetName() + ":Readable");
- writable_event = std::make_shared<KWritableEvent>(kernel, GetName() + ":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();
+ if (owner) {
+ owner->Open();
+ }
// Mark initialized.
+ name = std::move(name_);
initialized = true;
}
+void KEvent::Finalize() {
+ KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
+}
+
+void KEvent::PostDestroy(uintptr_t arg) {
+ // Release the event count resource the owner process holds.
+ KProcess* owner = reinterpret_cast<KProcess*>(arg);
+ if (owner) {
+ owner->GetResourceLimit()->Release(LimitableResource::Events, 1);
+ owner->Close();
+ }
+}
+
} // namespace Kernel