2018-06-10 10:06:50 +01: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-12 23:00:09 +01:00
|
|
|
static HosSemaphore g_sema_new_waitable_finish;
|
2018-06-10 10:06:50 +01:00
|
|
|
|
2018-06-19 19:07:31 +01:00
|
|
|
static std::unique_ptr<WaitableManager> g_worker_waiter;
|
2018-06-12 23:00:09 +01:00
|
|
|
|
2018-06-15 00:50:01 +01:00
|
|
|
Result FsMitMWorker::AddWaitableCallback(void *arg, Handle *handles, size_t num_handles, u64 timeout) {
|
|
|
|
(void)arg;
|
2018-06-10 10:06:50 +01:00
|
|
|
svcClearEvent(handles[0]);
|
2018-06-12 23:00:09 +01:00
|
|
|
g_sema_new_waitable_finish.Signal();
|
2018-06-10 10:06:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-15 00:50:01 +01:00
|
|
|
void FsMitMWorker::AddWaitable(IWaitable *waitable) {
|
2018-06-12 23:00:09 +01:00
|
|
|
g_worker_waiter->add_waitable(waitable);
|
2018-06-10 10:06:50 +01:00
|
|
|
g_new_waitable_mutex.Lock();
|
|
|
|
g_new_waitable_event->signal_event();
|
2018-06-12 23:00:09 +01:00
|
|
|
g_sema_new_waitable_finish.Wait();
|
2018-06-10 10:06:50 +01:00
|
|
|
g_new_waitable_mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
2018-06-15 00:50:01 +01:00
|
|
|
void FsMitMWorker::Main(void *arg) {
|
2018-06-10 10:06:50 +01:00
|
|
|
/* Initialize waitable event. */
|
2018-06-15 00:50:01 +01:00
|
|
|
g_new_waitable_event = new SystemEvent(NULL, &FsMitMWorker::AddWaitableCallback);
|
2018-06-10 10:06:50 +01:00
|
|
|
|
|
|
|
/* Make a new waitable manager. */
|
2018-06-19 19:07:31 +01:00
|
|
|
g_worker_waiter = std::make_unique<WaitableManager>(U64_MAX);
|
2018-06-12 23:00:09 +01:00
|
|
|
g_worker_waiter->add_waitable(g_new_waitable_event);
|
2018-06-10 10:06:50 +01:00
|
|
|
|
|
|
|
/* Service processes. */
|
2018-06-12 23:00:09 +01:00
|
|
|
g_worker_waiter->process();
|
2018-06-10 10:06:50 +01:00
|
|
|
}
|