From 700f92162dbea61b70728ee3de2de38e5118b4ab Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 6 May 2018 22:59:54 -0600 Subject: [PATCH] ProcessManager: Fix Synchronization. Now works on 1.0.0 hardware. --- .../include/stratosphere/systemevent.hpp | 2 +- stratosphere/pm/source/pm_process_track.cpp | 16 +++------------- stratosphere/pm/source/pm_registration.cpp | 15 +++++++++++---- stratosphere/pm/source/pm_registration.hpp | 3 ++- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/stratosphere/libstratosphere/include/stratosphere/systemevent.hpp b/stratosphere/libstratosphere/include/stratosphere/systemevent.hpp index 21545c5d8..55b4acdc2 100644 --- a/stratosphere/libstratosphere/include/stratosphere/systemevent.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/systemevent.hpp @@ -12,7 +12,7 @@ class SystemEvent : public IEvent { SystemEvent(EventCallback callback) : IEvent(0, callback) { Handle wait_h; Handle sig_h; - if (R_FAILED(svcCreateEvent(&wait_h, &sig_h))) { + if (R_FAILED(svcCreateEvent(&sig_h, &wait_h))) { /* TODO: Panic. */ } diff --git a/stratosphere/pm/source/pm_process_track.cpp b/stratosphere/pm/source/pm_process_track.cpp index 346d7079c..bb69c9092 100644 --- a/stratosphere/pm/source/pm_process_track.cpp +++ b/stratosphere/pm/source/pm_process_track.cpp @@ -6,22 +6,12 @@ void ProcessTracking::MainLoop(void *arg) { /* Make a new waitable manager. */ - WaitableManager *process_waiter = new WaitableManager(1000); + WaitableManager *process_waiter = new WaitableManager(U64_MAX); + process_waiter->add_waitable(Registration::GetProcessLaunchStartEvent()); process_waiter->add_waitable(Registration::GetProcessList()); - static unsigned int i = 0; /* Service processes. */ - while (true) { - process_waiter->process_until_timeout(); - - i++; - if (Registration::TryWaitProcessLaunchStartEvent()) { - Registration::HandleProcessLaunch(); - } - if (i > 1000000) { - Reboot(); - } - } + process_waiter->process(); delete process_waiter; svcExitThread(); diff --git a/stratosphere/pm/source/pm_registration.cpp b/stratosphere/pm/source/pm_registration.cpp index e28abfaf1..15c0b4ebc 100644 --- a/stratosphere/pm/source/pm_registration.cpp +++ b/stratosphere/pm/source/pm_registration.cpp @@ -8,7 +8,7 @@ static ProcessList g_process_list; static ProcessList g_dead_process_list; -static HosSemaphore g_sema_start_launch; +static SystemEvent *g_process_launch_start_event = NULL; static HosSemaphore g_sema_finish_launch; static HosMutex g_process_launch_mutex; @@ -61,6 +61,7 @@ void Registration::InitializeSystemResources() { g_process_event = new SystemEvent(&IEvent::PanicCallback); g_debug_title_event = new SystemEvent(&IEvent::PanicCallback); g_debug_application_event = new SystemEvent(&IEvent::PanicCallback); + g_process_launch_start_event = new SystemEvent(&Registration::ProcessLaunchStartCallback); /* Get memory limits. */ u64 memory_arrangement; @@ -111,8 +112,14 @@ void Registration::InitializeSystemResources() { } } -bool Registration::TryWaitProcessLaunchStartEvent() { - return g_sema_start_launch.TryWait(); +Result Registration::ProcessLaunchStartCallback(Handle *handles, size_t num_handles, u64 timeout) { + svcClearEvent(handles[0]); + Registration::HandleProcessLaunch(); + return 0; +} + +IWaitable *Registration::GetProcessLaunchStartEvent() { + return g_process_launch_start_event; } IWaitable *Registration::GetProcessList() { @@ -257,7 +264,7 @@ Result Registration::LaunchProcess(u64 title_id, FsStorageId storage_id, u64 lau g_process_launch_state.out_pid = out_pid; /* Start a launch, and wait for it to exit. */ - g_sema_start_launch.Signal(); + g_process_launch_start_event->signal_event(); g_sema_finish_launch.Wait(); rc = g_process_launch_state.result; diff --git a/stratosphere/pm/source/pm_registration.hpp b/stratosphere/pm/source/pm_registration.hpp index a50109140..e7e6697dd 100644 --- a/stratosphere/pm/source/pm_registration.hpp +++ b/stratosphere/pm/source/pm_registration.hpp @@ -41,7 +41,8 @@ class Registration { }; static void InitializeSystemResources(); - static bool TryWaitProcessLaunchStartEvent(); + static IWaitable *GetProcessLaunchStartEvent(); + static Result ProcessLaunchStartCallback(Handle *handles, size_t num_handles, u64 timeout); static IWaitable *GetProcessList(); static void HandleSignaledProcess(Process *process);