2018-09-07 16:00:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-02 15:10:57 +01:00
|
|
|
#include <mutex>
|
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-07-02 15:10:57 +01:00
|
|
|
std::scoped_lock lk{g_new_waitable_mutex};
|
2018-06-10 10:06:50 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|