forked from kentjhall/mizu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mizu.cpp
90 lines (78 loc) · 2.65 KB
/
mizu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <csignal>
#include <clocale>
#include <limits.h>
#include <sched.h>
#include <QApplication>
#include <QHBoxLayout>
#include "core/hle/service/service.h"
#include "core/hle/service/sm/sm.h"
#include "core/hle/kernel/code_set.h"
#include "common/logging/backend.h"
#include "common/logging/log.h"
#include "common/settings.h"
#include "configuration/config.h"
static void on_sig(int) {
// this allows logging to flush gracefully
::exit(1);
}
int main(int argc, char **argv) {
if (::signal(SIGINT, on_sig) == SIG_ERR) {
::perror("signal failed");
return 1;
}
if (::signal(SIGTERM, on_sig) == SIG_ERR) {
::perror("signal failed");
return 1;
}
if (::signal(SIGSEGV, on_sig) == SIG_ERR) {
::perror("signal failed");
return 1;
}
// stay off the first four CPUs if we've got extras to spare; this is where
// horizon tasks will live
cpu_set_t mask;
CPU_ZERO(&mask);
if (::sched_getaffinity(0, sizeof(mask), &mask) != 0) {
::perror("sched_getaffinity failed");
return 1;
}
for (int cpu = 0; cpu < 4 && CPU_COUNT(&mask) > 4; ++cpu)
CPU_CLR(cpu, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask) != 0) {
::perror("sched_setaffinity failed");
return 1;
}
QCoreApplication::setOrganizationName(QStringLiteral("Kent Hall"));
QCoreApplication::setApplicationName(QStringLiteral("mizu"));
// logger/config initialization
Common::Log::Initialize();
Config::config = std::make_shared<Config>();
// loader thread for handling launch requests
std::thread loader_thread(Loader::RunForever);
loader_thread.detach();
// setup for Qt
if (QString::fromLocal8Bit(qgetenv("DISPLAY")).isEmpty()) {
qputenv("DISPLAY", ":0");
}
QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QApplication app(argc, argv);
QWidget dummy; // prevents render window from telling the QApplication to exit
auto* layout = new QHBoxLayout(&dummy);
layout->setContentsMargins(0, 0, 0, 0);
dummy.setLayout(layout);
dummy.show();
setlocale(LC_ALL, "C");
// start service threads
Service::StartServices();
// service manager thread
std::thread sm_thread([](){
if (horizon_servctl(HZN_SCTL_REGISTER_NAMED_SERVICE, (unsigned long)"sm:") == -1) {
LOG_CRITICAL(Service, "HZN_SCTL_REGISTER_NAMED_SERVICE failed");
::exit(1);
}
Service::RunForever(Kernel::SessionRequestHandlerPtr(new Service::SM::SM));
});
sm_thread.detach();
return app.exec();
}