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.
This commit is contained in:
parent
3a33519598
commit
fadcee14f8
26 changed files with 367 additions and 271 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -127,8 +127,8 @@ public:
|
|||
explicit IBcatService(Core::System& system_, Backend& backend_)
|
||||
: ServiceFramework{system_, "IBcatService"}, backend{backend_},
|
||||
progress{{
|
||||
ProgressServiceBackend{system_.Kernel(), "Normal"},
|
||||
ProgressServiceBackend{system_.Kernel(), "Directory"},
|
||||
ProgressServiceBackend{system_, "Normal"},
|
||||
ProgressServiceBackend{system_, "Directory"},
|
||||
}} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue