8
8
#include " ReflectionHook.hxx"
9
9
#include " RemoteVM.hxx"
10
10
11
- auto create_command_processor = [](auto processor) {
11
+ auto create_command_processor = [](auto processor) -> std::thread {
12
12
std::thread thread = std::thread ([processor]{
13
13
#if defined(_WIN32) || defined(_WIN64)
14
14
HANDLE this_process = GetCurrentProcess ();
@@ -30,6 +30,7 @@ auto create_command_processor = [](auto processor) {
30
30
});
31
31
32
32
thread.detach ();
33
+ return thread;
33
34
};
34
35
35
36
ControlCenter::ControlCenter (std::int32_t pid, bool is_controller, std::unique_ptr<Reflection> reflector) : pid(pid), is_controller(is_controller), stopped(is_controller), command_signal(), response_signal(), sync_signal(), main_reflector(std::move(reflector)), io_controller(), remote_vm()
@@ -61,23 +62,7 @@ ControlCenter::ControlCenter(std::int32_t pid, bool is_controller, std::unique_p
61
62
62
63
if (this ->main_reflector )
63
64
{
64
- std::thread thread = std::thread ([this ]{
65
- #if defined(_WIN32) || defined(_WIN64)
66
- HANDLE this_process = GetCurrentProcess ();
67
- SetPriorityClass (this_process, NORMAL_PRIORITY_CLASS);
68
-
69
- HANDLE this_thread = GetCurrentThread ();
70
- SetThreadPriority (this_thread, THREAD_PRIORITY_HIGHEST);
71
- #else
72
- pthread_t this_thread = pthread_self ();
73
- if (this_thread)
74
- {
75
- struct sched_param params = {0 };
76
- params.sched_priority = sched_get_priority_max (SCHED_FIFO);
77
- pthread_setschedparam (this_thread, SCHED_FIFO, ¶ms);
78
- }
79
- #endif // defined
80
-
65
+ create_command_processor ([this ]{
81
66
if (this ->main_reflector ->Attach ())
82
67
{
83
68
this ->io_controller = std::make_unique<InputOutput>(this ->main_reflector .get ());
@@ -123,18 +108,32 @@ ControlCenter::ControlCenter(std::int32_t pid, bool is_controller, std::unique_p
123
108
{
124
109
this ->main_reflector .reset ();
125
110
}
111
+
112
+ response_signal->signal ();
126
113
}
127
114
});
128
-
129
- thread.detach ();
130
115
}
131
116
}
132
117
}
133
118
134
119
ControlCenter::~ControlCenter ()
135
120
{
136
121
terminate ();
137
- // main_reflector.reset();
122
+
123
+ if (sync_signal)
124
+ {
125
+ sync_signal.reset ();
126
+ }
127
+
128
+ if (command_signal)
129
+ {
130
+ command_signal.reset ();
131
+ }
132
+
133
+ if (response_signal)
134
+ {
135
+ response_signal.reset ();
136
+ }
138
137
139
138
if (memory_map)
140
139
{
@@ -158,6 +157,11 @@ void ControlCenter::terminate() noexcept
158
157
{
159
158
command_signal->signal ();
160
159
}
160
+
161
+ if (response_signal)
162
+ {
163
+ response_signal->wait ();
164
+ }
161
165
}
162
166
}
163
167
}
0 commit comments