2018-06-10 11:06:50 +02:00
|
|
|
#include <switch.h>
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "fsmitm_worker.hpp"
|
|
|
|
|
|
|
|
static SystemEvent *g_new_waitable_event = NULL;
|
|
|
|
|
|
|
|
static HosMutex g_new_waitable_mutex;
|
2018-06-13 00:00:09 +02:00
|
|
|
static HosSemaphore g_sema_new_waitable_finish;
|
2018-06-10 11:06:50 +02:00
|
|
|
|
2018-06-13 00:00:09 +02:00
|
|
|
static WaitableManager *g_worker_waiter = NULL;
|
|
|
|
|
|
|
|
Result FsMitmWorker::AddWaitableCallback(Handle *handles, size_t num_handles, u64 timeout) {
|
2018-06-10 11:06:50 +02:00
|
|
|
svcClearEvent(handles[0]);
|
2018-06-13 00:00:09 +02:00
|
|
|
g_sema_new_waitable_finish.Signal();
|
2018-06-10 11:06:50 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FsMitmWorker::AddWaitable(IWaitable *waitable) {
|
2018-06-13 00:00:09 +02:00
|
|
|
g_worker_waiter->add_waitable(waitable);
|
2018-06-10 11:06:50 +02:00
|
|
|
g_new_waitable_mutex.Lock();
|
|
|
|
g_new_waitable_event->signal_event();
|
2018-06-13 00:00:09 +02:00
|
|
|
g_sema_new_waitable_finish.Wait();
|
2018-06-10 11:06:50 +02:00
|
|
|
g_new_waitable_mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FsMitmWorker::Main(void *arg) {
|
|
|
|
/* Initialize waitable event. */
|
2018-06-13 00:00:09 +02:00
|
|
|
g_new_waitable_event = new SystemEvent(&FsMitmWorker::AddWaitableCallback);
|
2018-06-10 11:06:50 +02:00
|
|
|
|
|
|
|
/* Make a new waitable manager. */
|
2018-06-13 00:00:09 +02:00
|
|
|
g_worker_waiter = new WaitableManager(U64_MAX);
|
|
|
|
g_worker_waiter->add_waitable(g_new_waitable_event);
|
2018-06-10 11:06:50 +02:00
|
|
|
|
|
|
|
/* Service processes. */
|
2018-06-13 00:00:09 +02:00
|
|
|
g_worker_waiter->process();
|
2018-06-10 11:06:50 +02:00
|
|
|
|
2018-06-13 00:00:09 +02:00
|
|
|
delete g_worker_waiter;
|
2018-06-10 11:06:50 +02:00
|
|
|
}
|