ProcessManager: Fix Synchronization. Now works on 1.0.0 hardware.

This commit is contained in:
Michael Scire 2018-05-06 22:59:54 -06:00
parent 8d071ca7c9
commit 700f92162d
4 changed files with 17 additions and 19 deletions

View file

@ -12,7 +12,7 @@ class SystemEvent : public IEvent {
SystemEvent(EventCallback callback) : IEvent(0, callback) { SystemEvent(EventCallback callback) : IEvent(0, callback) {
Handle wait_h; Handle wait_h;
Handle sig_h; Handle sig_h;
if (R_FAILED(svcCreateEvent(&wait_h, &sig_h))) { if (R_FAILED(svcCreateEvent(&sig_h, &wait_h))) {
/* TODO: Panic. */ /* TODO: Panic. */
} }

View file

@ -6,22 +6,12 @@
void ProcessTracking::MainLoop(void *arg) { void ProcessTracking::MainLoop(void *arg) {
/* Make a new waitable manager. */ /* 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()); process_waiter->add_waitable(Registration::GetProcessList());
static unsigned int i = 0;
/* Service processes. */ /* Service processes. */
while (true) { process_waiter->process();
process_waiter->process_until_timeout();
i++;
if (Registration::TryWaitProcessLaunchStartEvent()) {
Registration::HandleProcessLaunch();
}
if (i > 1000000) {
Reboot();
}
}
delete process_waiter; delete process_waiter;
svcExitThread(); svcExitThread();

View file

@ -8,7 +8,7 @@
static ProcessList g_process_list; static ProcessList g_process_list;
static ProcessList g_dead_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 HosSemaphore g_sema_finish_launch;
static HosMutex g_process_launch_mutex; static HosMutex g_process_launch_mutex;
@ -61,6 +61,7 @@ void Registration::InitializeSystemResources() {
g_process_event = new SystemEvent(&IEvent::PanicCallback); g_process_event = new SystemEvent(&IEvent::PanicCallback);
g_debug_title_event = new SystemEvent(&IEvent::PanicCallback); g_debug_title_event = new SystemEvent(&IEvent::PanicCallback);
g_debug_application_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. */ /* Get memory limits. */
u64 memory_arrangement; u64 memory_arrangement;
@ -111,8 +112,14 @@ void Registration::InitializeSystemResources() {
} }
} }
bool Registration::TryWaitProcessLaunchStartEvent() { Result Registration::ProcessLaunchStartCallback(Handle *handles, size_t num_handles, u64 timeout) {
return g_sema_start_launch.TryWait(); svcClearEvent(handles[0]);
Registration::HandleProcessLaunch();
return 0;
}
IWaitable *Registration::GetProcessLaunchStartEvent() {
return g_process_launch_start_event;
} }
IWaitable *Registration::GetProcessList() { 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; g_process_launch_state.out_pid = out_pid;
/* Start a launch, and wait for it to exit. */ /* 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(); g_sema_finish_launch.Wait();
rc = g_process_launch_state.result; rc = g_process_launch_state.result;

View file

@ -41,7 +41,8 @@ class Registration {
}; };
static void InitializeSystemResources(); static void InitializeSystemResources();
static bool TryWaitProcessLaunchStartEvent(); static IWaitable *GetProcessLaunchStartEvent();
static Result ProcessLaunchStartCallback(Handle *handles, size_t num_handles, u64 timeout);
static IWaitable *GetProcessList(); static IWaitable *GetProcessList();
static void HandleSignaledProcess(Process *process); static void HandleSignaledProcess(Process *process);