From fadcee14f8fca1b76b4ea48b1cfd136ccae8d182 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 28 Sep 2021 23:42:50 -0400 Subject: service: Replace service event creation with ServiceContext::CreateEvent The service context helps to manage all created events and allows us to close them upon destruction. --- src/core/hle/service/bcat/backend/backend.cpp | 22 ++++++++++++---------- src/core/hle/service/bcat/backend/backend.h | 10 +++++++--- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'src/core/hle/service/bcat/backend') diff --git a/src/core/hle/service/bcat/backend/backend.cpp b/src/core/hle/service/bcat/backend/backend.cpp index a78544c88..4c7d3bb6e 100644 --- a/src/core/hle/service/bcat/backend/backend.cpp +++ b/src/core/hle/service/bcat/backend/backend.cpp @@ -5,22 +5,24 @@ #include "common/hex_util.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/kernel/k_readable_event.h" -#include "core/hle/kernel/k_writable_event.h" +#include "core/hle/kernel/k_event.h" #include "core/hle/lock.h" #include "core/hle/service/bcat/backend/backend.h" namespace Service::BCAT { -ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel, - std::string_view event_name) - : update_event{kernel} { - Kernel::KAutoObject::Create(std::addressof(update_event)); - update_event.Initialize("ProgressServiceBackend:UpdateEvent:" + std::string(event_name)); +ProgressServiceBackend::ProgressServiceBackend(Core::System& system, std::string_view event_name) + : service_context{system, "ProgressServiceBackend"} { + update_event = service_context.CreateEvent("ProgressServiceBackend:UpdateEvent:" + + std::string(event_name)); +} + +ProgressServiceBackend::~ProgressServiceBackend() { + service_context.CloseEvent(update_event); } Kernel::KReadableEvent& ProgressServiceBackend::GetEvent() { - return update_event.GetReadableEvent(); + return update_event->GetReadableEvent(); } DeliveryCacheProgressImpl& ProgressServiceBackend::GetImpl() { @@ -88,9 +90,9 @@ void ProgressServiceBackend::FinishDownload(ResultCode result) { void ProgressServiceBackend::SignalUpdate() { if (need_hle_lock) { std::lock_guard lock(HLE::g_hle_lock); - update_event.GetWritableEvent().Signal(); + update_event->GetWritableEvent().Signal(); } else { - update_event.GetWritableEvent().Signal(); + update_event->GetWritableEvent().Signal(); } } diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h index e79a9c2ad..749e046c7 100644 --- a/src/core/hle/service/bcat/backend/backend.h +++ b/src/core/hle/service/bcat/backend/backend.h @@ -11,8 +11,8 @@ #include "common/common_types.h" #include "core/file_sys/vfs_types.h" -#include "core/hle/kernel/k_event.h" #include "core/hle/result.h" +#include "core/hle/service/kernel_helpers.h" namespace Core { class System; @@ -70,6 +70,8 @@ class ProgressServiceBackend { friend class IBcatService; public: + ~ProgressServiceBackend(); + // Clients should call this with true if any of the functions are going to be called from a // non-HLE thread and this class need to lock the hle mutex. (default is false) void SetNeedHLELock(bool need); @@ -97,15 +99,17 @@ public: void FinishDownload(ResultCode result); private: - explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name); + explicit ProgressServiceBackend(Core::System& system, std::string_view event_name); Kernel::KReadableEvent& GetEvent(); DeliveryCacheProgressImpl& GetImpl(); void SignalUpdate(); + KernelHelpers::ServiceContext service_context; + DeliveryCacheProgressImpl impl{}; - Kernel::KEvent update_event; + Kernel::KEvent* update_event; bool need_hle_lock = false; }; -- cgit v1.2.3