2021-01-31 09:37:41 +00:00
|
|
|
// Copyright 2021 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "core/hle/kernel/k_event.h"
|
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2021-04-04 07:56:09 +00:00
|
|
|
#include "core/hle/kernel/k_resource_limit.h"
|
2021-01-31 09:37:41 +00:00
|
|
|
#include "core/hle/kernel/k_writable_event.h"
|
2021-04-04 07:56:09 +00:00
|
|
|
#include "core/hle/kernel/process.h"
|
2021-01-31 09:37:41 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-04-04 07:56:09 +00:00
|
|
|
KEvent::KEvent(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
2021-01-31 09:37:41 +00:00
|
|
|
|
|
|
|
KEvent::~KEvent() = default;
|
|
|
|
|
2021-04-04 07:56:09 +00:00
|
|
|
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();
|
2021-01-31 09:37:41 +00:00
|
|
|
|
|
|
|
// Create our sub events.
|
2021-04-04 07:56:09 +00:00
|
|
|
readable_event = std::make_shared<KReadableEvent>(kernel, name_ + ":Readable");
|
|
|
|
writable_event = std::make_shared<KWritableEvent>(kernel, name_ + ":Writable");
|
2021-01-31 09:37:41 +00:00
|
|
|
|
|
|
|
// Initialize our sub sessions.
|
|
|
|
readable_event->Initialize(this);
|
|
|
|
writable_event->Initialize(this);
|
|
|
|
|
2021-04-04 07:56:09 +00:00
|
|
|
// Set our owner process.
|
|
|
|
owner = kernel.CurrentProcess();
|
|
|
|
if (owner) {
|
|
|
|
owner->Open();
|
|
|
|
}
|
|
|
|
|
2021-01-31 09:37:41 +00:00
|
|
|
// Mark initialized.
|
2021-04-04 07:56:09 +00:00
|
|
|
name = std::move(name_);
|
2021-01-31 09:37:41 +00:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
2021-04-04 07:56:09 +00:00
|
|
|
void KEvent::Finalize() {
|
|
|
|
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEvent::PostDestroy(uintptr_t arg) {
|
|
|
|
// Release the event count resource the owner process holds.
|
|
|
|
Process* owner = reinterpret_cast<Process*>(arg);
|
|
|
|
if (owner) {
|
|
|
|
owner->GetResourceLimit()->Release(LimitableResource::Events, 1);
|
|
|
|
owner->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 09:37:41 +00:00
|
|
|
} // namespace Kernel
|