2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
#include "core/hle/kernel/k_event.h"
|
2021-04-24 01:04:28 -04:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2021-04-04 03:56:09 -04:00
|
|
|
#include "core/hle/kernel/k_resource_limit.h"
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-05-08 12:11:36 -04:00
|
|
|
KEvent::KEvent(KernelCore& kernel_)
|
|
|
|
: KAutoObjectWithSlabHeapAndContainer{kernel_}, readable_event{kernel_}, writable_event{
|
|
|
|
kernel_} {}
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
KEvent::~KEvent() = default;
|
|
|
|
|
2022-02-21 15:31:23 -05:00
|
|
|
void KEvent::Initialize(std::string&& name_, KProcess* owner_) {
|
2021-04-04 03:56:09 -04:00
|
|
|
// 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();
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
// Create our sub events.
|
2021-04-10 05:34:26 -04:00
|
|
|
KAutoObject::Create(std::addressof(readable_event));
|
|
|
|
KAutoObject::Create(std::addressof(writable_event));
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
// Initialize our sub sessions.
|
2021-04-10 05:34:26 -04:00
|
|
|
readable_event.Initialize(this, name_ + ":Readable");
|
|
|
|
writable_event.Initialize(this, name_ + ":Writable");
|
2021-01-31 04:37:41 -05:00
|
|
|
|
2021-04-04 03:56:09 -04:00
|
|
|
// Set our owner process.
|
2022-02-21 15:31:23 -05:00
|
|
|
owner = owner_;
|
|
|
|
owner->Open();
|
2021-04-04 03:56:09 -04:00
|
|
|
|
2021-01-31 04:37:41 -05:00
|
|
|
// Mark initialized.
|
2021-04-04 03:56:09 -04:00
|
|
|
name = std::move(name_);
|
2021-01-31 04:37:41 -05:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
2021-04-04 03:56:09 -04:00
|
|
|
void KEvent::Finalize() {
|
|
|
|
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEvent::PostDestroy(uintptr_t arg) {
|
|
|
|
// Release the event count resource the owner process holds.
|
2021-04-24 01:04:28 -04:00
|
|
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
2022-02-21 15:31:23 -05:00
|
|
|
owner->GetResourceLimit()->Release(LimitableResource::Events, 1);
|
|
|
|
owner->Close();
|
2021-04-04 03:56:09 -04:00
|
|
|
}
|
|
|
|
|
2021-01-31 04:37:41 -05:00
|
|
|
} // namespace Kernel
|