From addc0bf0379e075786048921bede6e089552a6db Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 4 Apr 2021 00:56:09 -0700 Subject: hle: kernel: Migrate KEvent to KAutoObject. --- src/core/hle/service/am/am.cpp | 82 +++++++++++++---------------- src/core/hle/service/am/am.h | 18 +++---- src/core/hle/service/am/applets/applets.cpp | 34 +++++------- src/core/hle/service/am/applets/applets.h | 7 +-- 4 files changed, 65 insertions(+), 76 deletions(-) (limited to 'src/core/hle/service/am') diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 7be94446a..3800c65ad 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -253,7 +253,8 @@ IDebugFunctions::IDebugFunctions(Core::System& system_) IDebugFunctions::~IDebugFunctions() = default; ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_) - : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_} { + : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, + launchable_event{system.Kernel()}, accumulated_suspended_tick_changed_event{system.Kernel()} { // clang-format off static const FunctionInfo functions[] = { {0, &ISelfController::Exit, "Exit"}, @@ -306,19 +307,17 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv RegisterHandlers(functions); - auto& kernel = system.Kernel(); - launchable_event = Kernel::KEvent::Create(kernel, "ISelfController:LaunchableEvent"); - launchable_event->Initialize(); + launchable_event.Initialize("ISelfController:LaunchableEvent"); // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple // ISelfControllers. The event is signaled on creation, and on transition from suspended -> not // suspended if the event has previously been created by a call to // GetAccumulatedSuspendedTickChangedEvent. - accumulated_suspended_tick_changed_event = - Kernel::KEvent::Create(kernel, "ISelfController:AccumulatedSuspendedTickChangedEvent"); - accumulated_suspended_tick_changed_event->Initialize(); - accumulated_suspended_tick_changed_event->GetWritableEvent()->Signal(); + + accumulated_suspended_tick_changed_event.Initialize( + "ISelfController:AccumulatedSuspendedTickChangedEvent"); + accumulated_suspended_tick_changed_event.GetWritableEvent()->Signal(); } ISelfController::~ISelfController() = default; @@ -377,11 +376,11 @@ void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) { void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); - launchable_event->GetWritableEvent()->Signal(); + launchable_event.GetWritableEvent()->Signal(); IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(launchable_event->GetReadableEvent()); + rb.PushCopyObjects(launchable_event.GetReadableEvent()); } void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) { @@ -560,7 +559,7 @@ void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequest IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent()); + rb.PushCopyObjects(accumulated_suspended_tick_changed_event.GetReadableEvent()); } void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) { @@ -578,38 +577,36 @@ void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestCo rb.Push(RESULT_SUCCESS); } -AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) { - on_new_message = Kernel::KEvent::Create(kernel, "AMMessageQueue:OnMessageReceived"); - on_new_message->Initialize(); - on_operation_mode_changed = - Kernel::KEvent::Create(kernel, "AMMessageQueue:OperationModeChanged"); - on_operation_mode_changed->Initialize(); +AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) + : on_new_message{kernel}, on_operation_mode_changed{kernel} { + on_new_message.Initialize("AMMessageQueue:OnMessageReceived"); + on_operation_mode_changed.Initialize("AMMessageQueue:OperationModeChanged"); } AppletMessageQueue::~AppletMessageQueue() = default; Kernel::KReadableEvent* AppletMessageQueue::GetMessageReceiveEvent() const { - return on_new_message->GetReadableEvent(); + return on_new_message.GetReadableEvent().get(); } Kernel::KReadableEvent* AppletMessageQueue::GetOperationModeChangedEvent() const { - return on_operation_mode_changed->GetReadableEvent(); + return on_operation_mode_changed.GetReadableEvent().get(); } void AppletMessageQueue::PushMessage(AppletMessage msg) { messages.push(msg); - on_new_message->GetWritableEvent()->Signal(); + on_new_message.GetWritableEvent()->Signal(); } AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() { if (messages.empty()) { - on_new_message->GetWritableEvent()->Clear(); + on_new_message.GetWritableEvent()->Clear(); return AppletMessage::NoMessage; } auto msg = messages.front(); messages.pop(); if (messages.empty()) { - on_new_message->GetWritableEvent()->Clear(); + on_new_message.GetWritableEvent()->Clear(); } return msg; } @@ -629,7 +626,7 @@ void AppletMessageQueue::FocusStateChanged() { void AppletMessageQueue::OperationModeChanged() { PushMessage(AppletMessage::OperationModeChanged); PushMessage(AppletMessage::PerformanceModeChanged); - on_operation_mode_changed->GetWritableEvent()->Signal(); + on_operation_mode_changed.GetWritableEvent()->Signal(); } ICommonStateGetter::ICommonStateGetter(Core::System& system_, @@ -1212,16 +1209,16 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex } auto transfer_mem = - system.CurrentProcess()->GetHandleTable().Get(handle); + system.CurrentProcess()->GetHandleTable().GetObject(handle); - if (transfer_mem == nullptr) { + if (transfer_mem.IsNull()) { LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_UNKNOWN); return; } - const u8* const mem_begin = transfer_mem->GetPointer(); + const u8* const mem_begin = system.Memory().GetPointer(transfer_mem->GetSourceAddress()); const u8* const mem_end = mem_begin + transfer_mem->GetSize(); std::vector memory{mem_begin, mem_end}; @@ -1265,7 +1262,9 @@ void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx) } IApplicationFunctions::IApplicationFunctions(Core::System& system_) - : ServiceFramework{system_, "IApplicationFunctions"} { + : ServiceFramework{system_, "IApplicationFunctions"}, gpu_error_detected_event{system.Kernel()}, + friend_invitation_storage_channel_event{system.Kernel()}, + health_warning_disappeared_system_event{system.Kernel()} { // clang-format off static const FunctionInfo functions[] = { {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, @@ -1334,15 +1333,11 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_) RegisterHandlers(functions); auto& kernel = system.Kernel(); - gpu_error_detected_event = - Kernel::KEvent::Create(kernel, "IApplicationFunctions:GpuErrorDetectedSystemEvent"); - gpu_error_detected_event->Initialize(); - friend_invitation_storage_channel_event = - Kernel::KEvent::Create(kernel, "IApplicationFunctions:FriendInvitationStorageChannelEvent"); - friend_invitation_storage_channel_event->Initialize(); - health_warning_disappeared_system_event = - Kernel::KEvent::Create(kernel, "IApplicationFunctions:HealthWarningDisappearedSystemEvent"); - health_warning_disappeared_system_event->Initialize(); + gpu_error_detected_event.Initialize("IApplicationFunctions:GpuErrorDetectedSystemEvent"); + friend_invitation_storage_channel_event.Initialize( + "IApplicationFunctions:FriendInvitationStorageChannelEvent"); + health_warning_disappeared_system_event.Initialize( + "IApplicationFunctions:HealthWarningDisappearedSystemEvent"); } IApplicationFunctions::~IApplicationFunctions() = default; @@ -1739,7 +1734,7 @@ void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestCon IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent()); + rb.PushCopyObjects(gpu_error_detected_event.GetReadableEvent()); } void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) { @@ -1747,7 +1742,7 @@ void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERe IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent()); + rb.PushCopyObjects(friend_invitation_storage_channel_event.GetReadableEvent()); } void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( @@ -1763,7 +1758,7 @@ void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERe IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent()); + rb.PushCopyObjects(health_warning_disappeared_system_event.GetReadableEvent()); } void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, @@ -1781,7 +1776,8 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger } IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) - : ServiceFramework{system_, "IHomeMenuFunctions"} { + : ServiceFramework{system_, "IHomeMenuFunctions"}, pop_from_general_channel_event{ + system.Kernel()} { // clang-format off static const FunctionInfo functions[] = { {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, @@ -1802,9 +1798,7 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) RegisterHandlers(functions); - pop_from_general_channel_event = - Kernel::KEvent::Create(system.Kernel(), "IHomeMenuFunctions:PopFromGeneralChannelEvent"); - pop_from_general_channel_event->Initialize(); + pop_from_general_channel_event.Initialize("IHomeMenuFunctions:PopFromGeneralChannelEvent"); } IHomeMenuFunctions::~IHomeMenuFunctions() = default; @@ -1821,7 +1815,7 @@ void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(Kernel::HLERequestContext IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent()); + rb.PushCopyObjects(pop_from_general_channel_event.GetReadableEvent()); } IGlobalStateController::IGlobalStateController(Core::System& system_) diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index f8daeb437..8f6017c4e 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -8,11 +8,11 @@ #include #include +#include "core/hle/kernel/k_event.h" #include "core/hle/service/service.h" namespace Kernel { class KernelCore; -class KEvent; class TransferMemory; } // namespace Kernel @@ -67,8 +67,8 @@ public: private: std::queue messages; - std::shared_ptr on_new_message; - std::shared_ptr on_operation_mode_changed; + Kernel::KEvent on_new_message; + Kernel::KEvent on_operation_mode_changed; }; class IWindowController final : public ServiceFramework { @@ -156,8 +156,8 @@ private: }; NVFlinger::NVFlinger& nvflinger; - std::shared_ptr launchable_event; - std::shared_ptr accumulated_suspended_tick_changed_event; + Kernel::KEvent launchable_event; + Kernel::KEvent accumulated_suspended_tick_changed_event; u32 idle_time_detection_extension = 0; u64 num_fatal_sections_entered = 0; @@ -300,9 +300,9 @@ private: bool launch_popped_application_specific = false; bool launch_popped_account_preselect = false; s32 previous_program_index{-1}; - std::shared_ptr gpu_error_detected_event; - std::shared_ptr friend_invitation_storage_channel_event; - std::shared_ptr health_warning_disappeared_system_event; + Kernel::KEvent gpu_error_detected_event; + Kernel::KEvent friend_invitation_storage_channel_event; + Kernel::KEvent health_warning_disappeared_system_event; }; class IHomeMenuFunctions final : public ServiceFramework { @@ -314,7 +314,7 @@ private: void RequestToGetForeground(Kernel::HLERequestContext& ctx); void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx); - std::shared_ptr pop_from_general_channel_event; + Kernel::KEvent pop_from_general_channel_event; }; class IGlobalStateController final : public ServiceFramework { diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index c093813fe..58bff810d 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -12,7 +12,6 @@ #include "core/frontend/applets/profile_select.h" #include "core/frontend/applets/software_keyboard.h" #include "core/frontend/applets/web_browser.h" -#include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_writable_event.h" #include "core/hle/kernel/server_session.h" @@ -31,16 +30,11 @@ namespace Service::AM::Applets { AppletDataBroker::AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_) - : system{system_}, applet_mode{applet_mode_} { - state_changed_event = - Kernel::KEvent::Create(system.Kernel(), "ILibraryAppletAccessor:StateChangedEvent"); - state_changed_event->Initialize(); - pop_out_data_event = - Kernel::KEvent::Create(system.Kernel(), "ILibraryAppletAccessor:PopDataOutEvent"); - pop_out_data_event->Initialize(); - pop_interactive_out_data_event = Kernel::KEvent::Create( - system.Kernel(), "ILibraryAppletAccessor:PopInteractiveDataOutEvent"); - pop_interactive_out_data_event->Initialize(); + : system{system_}, applet_mode{applet_mode_}, state_changed_event{system.Kernel()}, + pop_out_data_event{system.Kernel()}, pop_interactive_out_data_event{system.Kernel()} { + state_changed_event.Initialize("ILibraryAppletAccessor:StateChangedEvent"); + pop_out_data_event.Initialize("ILibraryAppletAccessor:PopDataOutEvent"); + pop_interactive_out_data_event.Initialize("ILibraryAppletAccessor:PopInteractiveDataOutEvent"); } AppletDataBroker::~AppletDataBroker() = default; @@ -67,7 +61,7 @@ std::shared_ptr AppletDataBroker::PopNormalDataToGame() { auto out = std::move(out_channel.front()); out_channel.pop_front(); - pop_out_data_event->GetWritableEvent()->Clear(); + pop_out_data_event.GetWritableEvent()->Clear(); return out; } @@ -86,7 +80,7 @@ std::shared_ptr AppletDataBroker::PopInteractiveDataToGame() { auto out = std::move(out_interactive_channel.front()); out_interactive_channel.pop_front(); - pop_interactive_out_data_event->GetWritableEvent()->Clear(); + pop_interactive_out_data_event.GetWritableEvent()->Clear(); return out; } @@ -105,7 +99,7 @@ void AppletDataBroker::PushNormalDataFromGame(std::shared_ptr&& storag void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr&& storage) { out_channel.emplace_back(std::move(storage)); - pop_out_data_event->GetWritableEvent()->Signal(); + pop_out_data_event.GetWritableEvent()->Signal(); } void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr&& storage) { @@ -114,11 +108,11 @@ void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr&& s void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr&& storage) { out_interactive_channel.emplace_back(std::move(storage)); - pop_interactive_out_data_event->GetWritableEvent()->Signal(); + pop_interactive_out_data_event.GetWritableEvent()->Signal(); } -void AppletDataBroker::SignalStateChanged() const { - state_changed_event->GetWritableEvent()->Signal(); +void AppletDataBroker::SignalStateChanged() { + state_changed_event.GetWritableEvent()->Signal(); switch (applet_mode) { case LibraryAppletMode::AllForeground: @@ -143,15 +137,15 @@ void AppletDataBroker::SignalStateChanged() const { } Kernel::KReadableEvent* AppletDataBroker::GetNormalDataEvent() const { - return pop_out_data_event->GetReadableEvent(); + return pop_out_data_event.GetReadableEvent().get(); } Kernel::KReadableEvent* AppletDataBroker::GetInteractiveDataEvent() const { - return pop_interactive_out_data_event->GetReadableEvent(); + return pop_interactive_out_data_event.GetReadableEvent().get(); } Kernel::KReadableEvent* AppletDataBroker::GetStateChangedEvent() const { - return state_changed_event->GetReadableEvent(); + return state_changed_event.GetReadableEvent().get(); } Applet::Applet(Core::System& system_, LibraryAppletMode applet_mode_) diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index ffde8ced0..327843a98 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -8,6 +8,7 @@ #include #include "common/swap.h" +#include "core/hle/kernel/k_event.h" #include "core/hle/kernel/object.h" union ResultCode; @@ -119,13 +120,13 @@ private: // PopInteractiveDataToGame and PushInteractiveDataFromApplet std::deque> out_interactive_channel; - std::shared_ptr state_changed_event; + Kernel::KEvent state_changed_event; // Signaled on PushNormalDataFromApplet - std::shared_ptr pop_out_data_event; + Kernel::KEvent pop_out_data_event; // Signaled on PushInteractiveDataFromApplet - std::shared_ptr pop_interactive_out_data_event; + Kernel::KEvent pop_interactive_out_data_event; }; class Applet { -- cgit v1.2.3