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 {
|
|
|
|
|
2023-03-07 10:49:41 -05:00
|
|
|
KEvent::KEvent(KernelCore& kernel)
|
|
|
|
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_readable_event{kernel} {}
|
2021-01-31 04:37:41 -05:00
|
|
|
|
|
|
|
KEvent::~KEvent() = default;
|
|
|
|
|
2022-10-12 20:26:04 -04:00
|
|
|
void KEvent::Initialize(KProcess* owner) {
|
|
|
|
// Create our readable event.
|
|
|
|
KAutoObject::Create(std::addressof(m_readable_event));
|
2021-01-31 04:37:41 -05:00
|
|
|
|
2022-10-12 20:26:04 -04:00
|
|
|
// Initialize our readable event.
|
|
|
|
m_readable_event.Initialize(this);
|
2021-01-31 04:37:41 -05:00
|
|
|
|
2021-04-04 03:56:09 -04:00
|
|
|
// Set our owner process.
|
2022-11-10 16:14:03 -05:00
|
|
|
// HACK: this should never be nullptr, but service threads don't have a
|
|
|
|
// proper parent process yet.
|
|
|
|
if (owner != nullptr) {
|
|
|
|
m_owner = owner;
|
|
|
|
m_owner->Open();
|
|
|
|
}
|
2021-04-04 03:56:09 -04:00
|
|
|
|
2021-01-31 04:37:41 -05:00
|
|
|
// Mark initialized.
|
2022-10-12 20:26:04 -04:00
|
|
|
m_initialized = true;
|
2021-01-31 04:37:41 -05:00
|
|
|
}
|
|
|
|
|
2021-04-04 03:56:09 -04:00
|
|
|
void KEvent::Finalize() {
|
|
|
|
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
|
|
|
|
}
|
|
|
|
|
2022-10-12 20:26:04 -04:00
|
|
|
Result KEvent::Signal() {
|
2023-03-07 10:49:41 -05:00
|
|
|
KScopedSchedulerLock sl{m_kernel};
|
2022-10-12 20:26:04 -04:00
|
|
|
|
|
|
|
R_SUCCEED_IF(m_readable_event_destroyed);
|
|
|
|
|
|
|
|
return m_readable_event.Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result KEvent::Clear() {
|
2023-03-07 10:49:41 -05:00
|
|
|
KScopedSchedulerLock sl{m_kernel};
|
2022-10-12 20:26:04 -04:00
|
|
|
|
|
|
|
R_SUCCEED_IF(m_readable_event_destroyed);
|
|
|
|
|
|
|
|
return m_readable_event.Clear();
|
|
|
|
}
|
|
|
|
|
2021-04-04 03:56:09 -04:00
|
|
|
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-11-10 16:14:03 -05:00
|
|
|
|
|
|
|
if (owner != nullptr) {
|
|
|
|
owner->GetResourceLimit()->Release(LimitableResource::EventCountMax, 1);
|
|
|
|
owner->Close();
|
|
|
|
}
|
2021-04-04 03:56:09 -04:00
|
|
|
}
|
|
|
|
|
2021-01-31 04:37:41 -05:00
|
|
|
} // namespace Kernel
|